Guest User

NodeAuditTrailWebScript

a guest
May 5th, 2018
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 22.87 KB | None | 0 0
  1. package com.eisenvault.repo.webscript;
  2.  
  3. import java.io.Serializable;
  4. import java.util.ArrayList;
  5. import java.util.Collections;
  6. import java.util.Comparator;
  7. import java.util.Date;
  8. import java.util.HashMap;
  9. import java.util.HashSet;
  10. import java.util.List;
  11. import java.util.Map;
  12. import java.util.Set;
  13. import java.util.stream.Collectors;
  14.  
  15. import org.alfresco.error.AlfrescoRuntimeException;
  16. import org.alfresco.model.ContentModel;
  17. import org.alfresco.repo.model.Repository;
  18. import org.alfresco.repo.security.authentication.AuthenticationUtil;
  19. import org.alfresco.repo.security.authentication.AuthenticationUtil.RunAsWork;
  20. import org.alfresco.service.cmr.audit.AuditQueryParameters;
  21. import org.alfresco.service.cmr.audit.AuditService;
  22. import org.alfresco.service.cmr.audit.AuditService.AuditQueryCallback;
  23. import org.alfresco.service.cmr.repository.NodeRef;
  24. import org.alfresco.service.cmr.repository.NodeService;
  25. import org.alfresco.service.namespace.QName;
  26. import org.apache.commons.lang.StringUtils;
  27. import org.apache.commons.logging.Log;
  28. import org.apache.commons.logging.LogFactory;
  29. import org.springframework.extensions.webscripts.Cache;
  30. import org.springframework.extensions.webscripts.DeclarativeWebScript;
  31. import org.springframework.extensions.webscripts.Status;
  32. import org.springframework.extensions.webscripts.WebScriptRequest;
  33.  
  34. public class NodeAuditTrailWebScript extends DeclarativeWebScript {
  35. private static Log logger = LogFactory.getLog(NodeAuditTrailWebScript.class);
  36.  
  37. /** Audit related */
  38. private static final String EV_AUDIT_APPLICATION_NAME = "alfresco-access";
  39. private static final String EV_AUDIT_APPLICATION_NAME_ROOT_PATH = "alfresco-access";
  40. private static final String EV_AUDIT_NODE_PATH = "/alfresco-access/transaction/node";
  41. private static final String EV_AUDIT_ACTION_PATH = "/alfresco-access/transaction/action";
  42. private static final String EV_AUDIT_SUB_ACTIONS_PATH = "/alfresco-access/transaction/sub-actions";
  43. private static final String EV_AUDIT_USER_PATH = "/alfresco-access/transaction/user";
  44. private static final String EV_AUDIT_DOC_PATH = "/alfresco-access/transaction/path";
  45. private static final String EV_AUDIT_TYPE_PATH = "/alfresco-access/transaction/type";
  46. private static final String EV_AUDIT_VERSION_LABEL_PATH = "/alfresco-access/transaction/cm:versionLabel";
  47. private static final String EV_AUDIT_COPY_FROM_PATH = "/alfresco-access/transaction/copy/from/path";
  48. private static final String EV_AUDIT_MOVE_FROM_PATH = "/alfresco-access/transaction/move/from/path";
  49. private static final String EV_AUDIT_PROP_FROM_NAME_PATH = "/alfresco-access/transaction/properties/from/name";
  50. private static final String EV_AUDIT_PROP_TO_NAME_PATH = "/alfresco-access/transaction/properties/to/name";
  51. private static final String EV_AUDIT_PROP_FROM_PATH = "/alfresco-access/transaction/properties/from";
  52. private static final String EV_AUDIT_PROP_TO_PATH = "/alfresco-access/transaction/properties/to";
  53. private static final String EV_AUDIT_PROP_ADD_PATH = "/alfresco-access/transaction/properties/add";
  54. private static final String EV_AUDIT_PROP_DELETE_PATH = "/alfresco-access/transaction/properties/delete";
  55. private static final String EV_AUDIT_ASPECTS_ADD_PATH = "/alfresco-access/transaction/aspects/add";
  56. private static final String EV_AUDIT_ASPECTS_DELETE_PATH = "/alfresco-access/transaction/aspects/delete";
  57.  
  58. /** Audit actions */
  59. private static final String EV_AUDIT_ACTION_UPDATE_NODE_PROP = "updateNodeProperties";
  60. private static final String EV_AUDIT_ACTION_READ = "READ";
  61. private static final String EV_AUDIT_ACTION_READ_CONTENT = "readContent";
  62. private static final String EV_AUDIT_ACTION_ADD_NODE_ASPECT = "addNodeAspect";
  63. private static final String EV_AUDIT_ACTION_DELETE_NODE_ASPECT = "deleteNodeAspect";
  64.  
  65. /** Audit actions show */
  66. private static final String EV_AUDIT_ACTION_UPDATE_NODE_PROP_SHOW = "PROPERTIES UPDATED";
  67. private static final String EV_AUDIT_ACTION_READ_SHOW = "READ";
  68. private static final String EV_AUDIT_ACTION_READ_CONTENT_SHOW = "READ CONTENT";
  69. private static final String EV_AUDIT_ACTION_DOWNLOAD_SHOW = "VIEW IN BROWSER/DOWNLOAD";
  70. private static final String EV_AUDIT_ACTION_ADD_NODE_ASPECT_SHOW = "ASPECT ADDED";
  71. private static final String EV_AUDIT_ACTION_DELETE_NODE_ASPECT_SHOW = "ASPECT DELETED";
  72.  
  73. /** Services required by class */
  74. private NodeService nodeService;
  75. private AuditService auditService;
  76. private Repository repository;
  77.  
  78. /** Services setter method */
  79. public void setNodeService(NodeService nodeService) {
  80. this.nodeService = nodeService;
  81. }
  82.  
  83. public void setAuditService(AuditService auditService) {
  84. this.auditService = auditService;
  85. }
  86.  
  87. public void setRepository(Repository repository) {
  88. this.repository = repository;
  89. }
  90.  
  91. @Override
  92. protected Map<String, Object> executeImpl(WebScriptRequest req,
  93. Status status, Cache cache) {
  94. Map<String, Object> model = new HashMap<String, Object>();
  95.  
  96. try {
  97. String nodeRefString = req.getParameter("nodeRef");
  98. if (StringUtils.isBlank(nodeRefString))
  99. throw new Exception("'nodeRef' missing while processing request...");
  100.  
  101. nodeRefString = nodeRefString.replace(":/", "");
  102. NodeRef nodeRef = repository.findNodeRef("node", nodeRefString.split("/"));
  103.  
  104. List<TemplateAuditInfo> auditTrailList = getAuditTrail(nodeRef);
  105. List<Map<String, Object>> auditList = new ArrayList<Map<String, Object>>(
  106. auditTrailList.size());
  107.  
  108. for (TemplateAuditInfo auditInfo : auditTrailList) {
  109. if (logger.isDebugEnabled()) {
  110. logger.debug("\n\n" + auditInfo.toString() + "\n\n");
  111. }
  112. Map<String, Object> auditInfoMap = new HashMap<String, Object>();
  113. auditInfoMap.put("userName", auditInfo.getUserIdentifier());
  114. auditInfoMap.put("applicationName", auditInfo.getAuditApplication());
  115. auditInfoMap.put("applicationMethod", auditInfo.getAuditMethod());
  116. auditInfoMap.put("date", auditInfo.getDate());
  117. auditInfoMap.put("propertiesUpdate", auditInfo.getUpdatedPropertiesList());
  118. if(auditInfo.getAuditMethod().equals(EV_AUDIT_ACTION_UPDATE_NODE_PROP_SHOW) && auditInfo.getUpdatedPropertiesList().size() == 0){
  119. continue;
  120. }
  121. auditList.add(auditInfoMap);
  122. }
  123. Map<QName, Serializable> props = nodeService.getProperties(nodeRef);
  124. String fileName = (String) props.get(ContentModel.PROP_NAME);
  125.  
  126. model.put("data", auditList);
  127. model.put("nodeRef", nodeRef.getId());
  128. model.put("fileName", fileName);
  129. model.put("count", auditList.size());
  130. model.put("returnStatus", Boolean.TRUE);
  131. model.put("statusMessage", "Successfully retrieved audit trail for nodeRef[" + nodeRef + "]");
  132.  
  133. } catch (Exception e) {
  134. logger.warn(e.getMessage());
  135. model.put("returnStatus", Boolean.FALSE);
  136. model.put("statusMessage", e.getMessage());
  137. }
  138. return model;
  139. }
  140.  
  141. private List<TemplateAuditInfo> getAuditTrail(final NodeRef nodeRef) {
  142. final List<TemplateAuditInfo> result = new ArrayList<TemplateAuditInfo>();
  143.  
  144. final AuditQueryCallback callback = new AuditQueryCallback() {
  145.  
  146. public boolean valuesRequired() {
  147. return true;
  148. }
  149.  
  150. public boolean handleAuditEntryError(Long entryId, String errorMsg,
  151. Throwable error) {
  152. throw new AlfrescoRuntimeException(
  153. "Failed to retrieve audit data.", error);
  154. }
  155.  
  156. public boolean handleAuditEntry(Long entryId,
  157. String applicationName, String userName, long time,
  158. Map<String, Serializable> values) {
  159. TemplateAuditInfo auditInfo = new TemplateAuditInfo(
  160. applicationName, userName, time, values);
  161. result.add(auditInfo);
  162. return true;
  163. }
  164. };
  165.  
  166.  
  167. AuthenticationUtil.runAs(new RunAsWork<Object>() {
  168. public Object doWork() throws Exception {
  169. AuditQueryParameters pathParams = new AuditQueryParameters();
  170. pathParams.setApplicationName(EV_AUDIT_APPLICATION_NAME);
  171. pathParams.addSearchKey(EV_AUDIT_NODE_PATH, nodeRef);
  172. auditService.auditQuery(callback, pathParams, 1000);
  173. return null;
  174. }
  175. }, AuthenticationUtil.getAdminUserName());
  176.  
  177. // sort audit entries by time of generation
  178. Collections.sort(result, new Comparator<TemplateAuditInfo>() {
  179. public int compare(TemplateAuditInfo o1, TemplateAuditInfo o2) {
  180. return o1.getDate().compareTo(o2.getDate());
  181. }
  182. });
  183. return result;
  184. }
  185.  
  186. public class TemplateAuditInfo {
  187. private String applicationName;
  188. private String userName;
  189. private long time;
  190. private Map<String, Serializable> values;
  191.  
  192. public TemplateAuditInfo(String applicationName, String userName,
  193. long time, Map<String, Serializable> values) {
  194. this.applicationName = applicationName;
  195. this.userName = userName;
  196. this.time = time;
  197. this.values = values;
  198. }
  199.  
  200. public String getAuditApplication() {
  201. return this.applicationName;
  202. }
  203.  
  204. public String getUserIdentifier() {
  205. return this.userName;
  206. }
  207.  
  208. public Date getDate() {
  209. return new Date(time);
  210. }
  211.  
  212. public String getAuditMethod() {
  213. if (this.values.get(EV_AUDIT_ACTION_PATH).equals(EV_AUDIT_ACTION_UPDATE_NODE_PROP)){
  214. return EV_AUDIT_ACTION_UPDATE_NODE_PROP_SHOW;
  215. } else if (this.values.get(EV_AUDIT_ACTION_PATH).equals(EV_AUDIT_ACTION_READ_CONTENT)) {
  216. return EV_AUDIT_ACTION_READ_CONTENT_SHOW;
  217. } else if (this.values.get(EV_AUDIT_ACTION_PATH).equals(EV_AUDIT_ACTION_READ)) {
  218. // list = [png, pdf, jpg, jpeg]
  219. // return "READ CONTENT OR VIEW IN BROWSER/DOWNLOAD" in case of list else return VIEW IN BROWSER/DOWNLOAD
  220. // as there is no difference between READ & READ CONTENT in case of list
  221. String docPath = (String) this.values.get(EV_AUDIT_DOC_PATH);
  222. String[] docPathArr = docPath.split("/");
  223. String docName = docPathArr[docPathArr.length - 1];
  224.  
  225. String docNameArr[] = docName.split("\\.");
  226. String docExt = docNameArr[docNameArr.length - 1];
  227.  
  228. logger.debug("\n\n\n\n The " + docName + " extension is " + docExt + " \n\n\n\n");
  229.  
  230. if("pdf".equals(docExt) || "png".equals(docExt) || "jpg".equals(docExt) || "jpeg".equals(docExt) || "dwg".equals(docExt))
  231. return EV_AUDIT_ACTION_READ_SHOW + " OR " + EV_AUDIT_ACTION_DOWNLOAD_SHOW;
  232. return EV_AUDIT_ACTION_DOWNLOAD_SHOW;
  233. } else if (this.values.get(EV_AUDIT_ACTION_PATH).equals(EV_AUDIT_ACTION_ADD_NODE_ASPECT)) {
  234. return EV_AUDIT_ACTION_ADD_NODE_ASPECT_SHOW;
  235. }else if (this.values.get(EV_AUDIT_ACTION_PATH).equals(EV_AUDIT_ACTION_DELETE_NODE_ASPECT)) {
  236. return EV_AUDIT_ACTION_DELETE_NODE_ASPECT_SHOW;
  237. }else
  238. return this.values.get(EV_AUDIT_ACTION_PATH).toString();
  239. }
  240.  
  241. public Map<String, Serializable> getValues() {
  242. return this.values;
  243. }
  244.  
  245. public List<String> getUpdatedPropertiesList() {
  246.  
  247. String objectType;
  248.  
  249. // This list will be returned containing the string declaring properties updated from-->to
  250. List<String> propertiesUpdatedFromAfter = new ArrayList<String>();
  251.  
  252. // get the value that are updated
  253. if (this.values.get(EV_AUDIT_PROP_FROM_PATH) != null) {
  254.  
  255. // Get the map of properties that are updated
  256. Map<QName, Serializable> beforeProperties = (Map<QName, Serializable>) this.values.get(EV_AUDIT_PROP_FROM_PATH);
  257. Map<QName, Serializable> afterProperties = (Map<QName, Serializable>) this.values.get(EV_AUDIT_PROP_TO_PATH);
  258.  
  259. logger.debug(" \n\n$$$$$$$$$$$$$$$$\n\n Printing out keys of the beforeProperties map " + beforeProperties.keySet() + " \n\n$$$$$$$$$$$$$$$$\n\n");
  260. logger.debug(" \n\n$$$$$$$$$$$$$$$$\n\n Printing out values of the beforeProperties map " + beforeProperties.values() + " \n\n$$$$$$$$$$$$$$$$\n\n");
  261. logger.debug(" \n\n$$$$$$$$$$$$$$$$\n\n Printing out values of the afterProperties map " + afterProperties.values() + " \n\n$$$$$$$$$$$$$$$$\n\n");
  262.  
  263. for(QName qname : beforeProperties.keySet()){
  264.  
  265. // need to check the type of values returned
  266. objectType = getObjectType(beforeProperties.get(qname));
  267.  
  268. // Creating object based on the return value of objectType
  269. if("String".equals(objectType)){
  270. String propBefore = (String) beforeProperties.get(qname);
  271. String propAfter = (String) afterProperties.get(qname);
  272.  
  273. logger.debug("\n\n$$$$$$$$$$$$$$$\n\n . Property '" + qname.getLocalName() + "' updated from: '" + propBefore
  274. + "' to: '" + propAfter + "' \n\n$$$$$$$$$$$$$$$$\n\n");
  275. propertiesUpdatedFromAfter.add(". Property '" + qname.getLocalName() + "' updated from: '" + propBefore
  276. + "' to: '" + propAfter + "'");
  277.  
  278. }else if("Map".equals(objectType)){
  279. Map propBefore = (Map) beforeProperties.get(qname);
  280. Map propAfter = (Map) afterProperties.get(qname);
  281.  
  282. if(ContentModel.PROP_TITLE.equals(qname) || ContentModel.PROP_DESCRIPTION.equals(qname)){
  283. // propBefore.values() and propAfter.values() gives us a list
  284. // converting them to comma separated values
  285. logger.debug(" \n\n$$$$$$$$$$$$$$$$\n\n . Property " + qname.getLocalName() + " updated from: " + String.join(",", propBefore.values())
  286. + " to: " + String.join(",", propAfter.values()) + " \n\n$$$$$$$$$$$$$$$$\n\n");
  287. propertiesUpdatedFromAfter.add(". Property '" + qname.getLocalName() + "' updated from: '" + String.join(",", propBefore.values())
  288. + "' to: '" + String.join(",", propAfter.values()) + "'");
  289. }
  290. }else if("List".equals(objectType)){
  291. List propBefore = (List) beforeProperties.get(qname);
  292. List propAfter = (List) afterProperties.get(qname);
  293. if(qname.equals(ContentModel.PROP_TAGS)){
  294. // propAdd contains a list of noderefs for tags; we need to get the values from those noderefs
  295. // propBefore and propAfter can come with size 0 if the List object sent to getTaggablePropValue is null
  296. propBefore = getTaggablePropValue(propBefore);
  297. propAfter = getTaggablePropValue(propAfter);
  298.  
  299. logger.debug(" \n\n$$$$$$$$$$$$$$$$\n\n . Property " + qname.getLocalName() + " updated from: " + String.join(",", propBefore)
  300. + " to: " + String.join(",", propAfter) + " \n\n$$$$$$$$$$$$$$$$\n\n");
  301. propertiesUpdatedFromAfter.add(". Property '" + qname.getLocalName() + "' updated from: '" + propBefore.stream()
  302. .collect(Collectors.joining(",")) + " to: " + String.join(",", propAfter) + "'");
  303. }
  304. }else if("Date".equals(objectType)){
  305. Date propBefore = (Date) beforeProperties.get(qname);
  306. Date propAfter = (Date) afterProperties.get(qname);
  307. if(ContentModel.PROP_MODIFIED.equals(qname)){
  308. // don't add this to list as modified value is of no use
  309. }else{
  310. logger.debug(" \n\n$$$$$$$$$$$$$$$$\n\n . Property " + qname.getLocalName() + " updated from: " + propBefore
  311. + " to: " + propAfter + " \n\n$$$$$$$$$$$$$$$$\n\n");
  312. propertiesUpdatedFromAfter.add(". Property '" + qname.getLocalName() + "' updated from: '" + propBefore
  313. + " to: " + propAfter + "'");
  314. }
  315. }else if("Long".equals(objectType)){
  316. Long propBefore = (Long) beforeProperties.get(qname);
  317. Long propAfter = (Long) afterProperties.get(qname);
  318.  
  319. logger.debug(" \n\n$$$$$$$$$$$$$$$$\n\n . Property " + qname.getLocalName() + " updated from: " + propBefore
  320. + " to: " + propAfter + " \n\n$$$$$$$$$$$$$$$$\n\n");
  321. propertiesUpdatedFromAfter.add(". Property '" + qname.getLocalName() + "' updated from: '" + propBefore
  322. + " to: " + propAfter + "'");
  323.  
  324. }
  325. }
  326. }
  327.  
  328. // get the value that are added
  329. if (this.values.get(EV_AUDIT_PROP_ADD_PATH) != null){
  330.  
  331. // Get the map of properties that are added
  332. Map<QName, Serializable> addedProperties = (Map<QName, Serializable>) this.values.get(EV_AUDIT_PROP_ADD_PATH);
  333. logger.debug("\n\n**************\n\n Printing out keys of the addedProperties map " + addedProperties.keySet() + " \n\n**************\n\n");
  334. logger.debug("\n\n**************\n\n Printing out values of the addedProperties map " + addedProperties.values() + " \n\n**************\n\n");
  335.  
  336. for(QName qname : addedProperties.keySet()){
  337. // need to check the type of values returned
  338. objectType = getObjectType(addedProperties.get(qname));
  339.  
  340. if("String".equals(objectType)){
  341. String propAdd = (String) addedProperties.get(qname);
  342.  
  343. logger.debug("\n\n**************\n\n . Property " + qname.getLocalName() + " added with value " + propAdd
  344. + " \n\n**************\n\n ");
  345. propertiesUpdatedFromAfter.add(". Property '" + qname.getLocalName() + "' added with value '" + propAdd + "'");
  346.  
  347. }else if("Map".equals(objectType)){
  348. Map propAdd = (Map) addedProperties.get(qname);
  349.  
  350. if(ContentModel.PROP_TITLE.equals(qname) || ContentModel.PROP_DESCRIPTION.equals(qname)){
  351. logger.debug("\n\n**************\n\n . Property " + qname.getLocalName() + " added with value " + String.join(",", propAdd.values())
  352. + " \n\n**************\n\n ");
  353. propertiesUpdatedFromAfter.add(". Property '" + qname.getLocalName() + "' added with value '" + String.join(",", propAdd.values()) + "'");
  354. }
  355. }else if("List".equals(objectType)){
  356. List propAdd = (List) addedProperties.get(qname);
  357. if(qname.equals(ContentModel.PROP_TAGS)){
  358. // propAdd contains a list of noderefs for tags; we need to get the values from those noderefs
  359. // propAdd can come with size 0 if the List object sent to getTaggablePropValue is null
  360. propAdd = getTaggablePropValue(propAdd);
  361.  
  362. logger.debug("\n\n**************\n\n . Property " + qname.getLocalName() + " added with value " + String.join(",", propAdd)
  363. + " \n\n**************\n\n ");
  364. propertiesUpdatedFromAfter.add(". Property '" + qname.getLocalName() + "' added with value '" + String.join(",", propAdd) + "'");
  365. }
  366. }else if("Date".equals(objectType)){
  367. Date propAdd = (Date) addedProperties.get(qname);
  368.  
  369. logger.debug("\n\n**************\n\n . Property " + qname.getLocalName() + " added with value " + propAdd
  370. + "\n\n**************\n\n ");
  371. propertiesUpdatedFromAfter.add(". Property '" + qname.getLocalName() + "' added with value '" + propAdd + "'");
  372.  
  373. }else if("Long".equals(objectType)){
  374. Long propAdd = (Long) addedProperties.get(qname);
  375.  
  376. logger.debug("\n\n**************\n\n . Property " + qname.getLocalName() + " added with value " + propAdd
  377. + " \n\n**************\n\n ");
  378. propertiesUpdatedFromAfter.add(". Property '" + qname.getLocalName() + "' added with value '" + propAdd + "'");
  379.  
  380. }
  381. }
  382. }
  383.  
  384. // Get the aspects that are added
  385. if(this.values.get(EV_AUDIT_ASPECTS_ADD_PATH) != null){
  386. Set<QName> aspectsAddList = (Set<QName>)this.values.get(EV_AUDIT_ASPECTS_ADD_PATH);
  387. logger.debug(" \n\n^^^^^^^^^^^^^\n\n Printing out values of the aspectsAddList list " + aspectsAddList + " \n\n^^^^^^^^^^^^^\n\n");
  388.  
  389. Set<String> aspects = new HashSet<>();
  390.  
  391. for(QName qName : aspectsAddList){
  392. logger.debug("Getting localname for qname " + qName.getLocalName());
  393. aspects.add(qName.getLocalName());
  394. }
  395. logger.debug("\n\n^^^^^^^^^^^^^\n\n . Aspect " + String.join(",", aspects) + " added \n\n^^^^^^^^^^^^^\n\n");
  396. propertiesUpdatedFromAfter.add(". Aspect(s) '" + String.join(",", aspects) + "' added");
  397.  
  398. // Trying with java 8 but not working :(
  399. /*String citiesCommaSeparated = aspectsAddList.stream().map(i -> i.getLocalName()).collect(Collectors.joining(","));
  400. logger.debug("************** \n\n\n\n Aspect " + citiesCommaSeparated + " added \n\n\n\n **************");
  401. propertiesUpdatedFromAfter.add("Aspect " + citiesCommaSeparated + " added");*/
  402. }
  403.  
  404. // Get the aspects that are deleted
  405. if(this.values.get(EV_AUDIT_ASPECTS_DELETE_PATH) != null){
  406. Set<QName> aspectsDeleteList = (Set<QName>)this.values.get(EV_AUDIT_ASPECTS_DELETE_PATH);
  407. logger.debug("\n\n&&&&&&&&&&&&\n\n Printing out values of the aspectsDeleteList list " + aspectsDeleteList + " \n\n&&&&&&&&&&&&\n\n");
  408.  
  409. Set<String> aspects = new HashSet<>();
  410.  
  411. for(QName qName : aspectsDeleteList){
  412. logger.debug("Getting localname for qname " + qName);
  413. aspects.add(qName.getLocalName());
  414. }
  415. logger.debug("\n\n&&&&&&&&&&&&\n\n . Aspect " + String.join(",", aspects) + " removed \n\n&&&&&&&&&&&&\n\n");
  416. propertiesUpdatedFromAfter.add(". Aspect(s) '" + String.join(",", aspects) + "' removed");
  417. }
  418.  
  419. // Get the move path from
  420. if(this.values.get(EV_AUDIT_MOVE_FROM_PATH) != null){
  421. String moveFromPath = (String)this.values.get(EV_AUDIT_MOVE_FROM_PATH);
  422. String moveToPath = (String)this.values.get(EV_AUDIT_DOC_PATH);
  423.  
  424. moveFromPath = moveFromPath.replace(("/app:company_home/st:sites"),"");
  425. moveToPath = moveToPath.replace(("/app:company_home/st:sites"),"");
  426.  
  427. logger.debug("\n\n#############\n\n . Moved from " + moveFromPath + " to " + moveToPath + " \n\n#############\n\n");
  428. propertiesUpdatedFromAfter.add(". Moved from '" + moveFromPath + "' to '" + moveToPath + "'");
  429. }
  430.  
  431. // Get the copy path from
  432. if(this.values.get(EV_AUDIT_COPY_FROM_PATH) != null){
  433. String copyFromPath = (String)this.values.get(EV_AUDIT_COPY_FROM_PATH);
  434. String copyToPath = (String)this.values.get(EV_AUDIT_DOC_PATH);
  435.  
  436. copyFromPath = copyFromPath.replace(("/app:company_home/st:sites"),"");
  437. copyToPath = copyToPath.replace(("/app:company_home/st:sites"),"");
  438.  
  439. logger.debug("\n\n#############\n\n . Copied from " + copyFromPath + " to " + copyToPath + " \n\n#############\n\n");
  440. propertiesUpdatedFromAfter.add(". Copied from '" + copyFromPath + "' to '" + copyToPath + "'");
  441. }
  442. return propertiesUpdatedFromAfter;
  443. }
  444.  
  445. /**
  446. *
  447. * @param taggablePropertyValue
  448. * @return String:tagNames.toString()
  449. *
  450. * Returns tag names from their respective nodeRef
  451. */
  452. public List<String> getTaggablePropValue(List<NodeRef> tagsNodeRef) {
  453.  
  454. List<String> tagsNames = new ArrayList<>();
  455. if(tagsNodeRef == null){
  456. return tagsNames;
  457. }
  458. for (int i = 0; i < tagsNodeRef.size(); i++) {
  459. tagsNames.add((String) nodeService.getProperty(tagsNodeRef.get(i), ContentModel.PROP_NAME));
  460. }
  461. return tagsNames;
  462. }
  463.  
  464. /**
  465. *
  466. * @param object
  467. * @return String:objectType
  468. *
  469. * Get the object type for the values map values
  470. */
  471. public String getObjectType(Serializable object){
  472. String objectType = null;
  473. if(object instanceof String){
  474. objectType = "String";
  475. }else if(object instanceof Map){
  476. objectType = "Map";
  477. }else if(object instanceof List){
  478. objectType = "List";
  479. }else if(object instanceof Date){
  480. objectType = "Date";
  481. }else if(object instanceof Long){
  482. objectType = "Long";
  483. }
  484.  
  485. logger.debug("\t\t Got " +objectType+ " type \t\t");
  486. return objectType;
  487. }
  488.  
  489. public String toString() {
  490. return "TemplateAuditInfo [applicationName=" + applicationName
  491. + ",userName= " + userName + ",time= " + time + ",values= "
  492. + values + "]";
  493. }
  494. }
  495. }
Add Comment
Please, Sign In to add comment