@Test public void shouldDoNothingWhenOriginatingUserIsSystem() { DocumentModel doc = session.createDocumentModel("/", "file", "File"); Map<String, Object> originalProperties = new HashMap<>(doc.getProperties("dublincore")); Event event = getEventFromDocumentContext(BEFORE_DOC_UPDATE, session, new SystemPrincipal(null)); storageService.addContributor(doc, event); assertDocumentPropertiesChanges(doc, originalProperties, new HashSet<>()); }
@Override public void addContributor(DocumentModel doc, Event event) { NuxeoPrincipal principal = Objects.requireNonNull(event.getContext().getPrincipal()); String principalName = principal.getActingUser(); if (principal instanceof SystemPrincipal && SYSTEM_USERNAME.equals(principalName) && !ABOUT_TO_CREATE.equals(event.getName())) { return; } List<String> contributorsList = getSanitizedExistingContributors(doc); if (!contributorsList.contains(principalName)) { contributorsList.add(principalName); } Framework.doPrivileged(() -> { if (doc.getPropertyValue(DUBLINCORE_CREATOR_PROPERTY) == null) { doc.setPropertyValue(DUBLINCORE_CREATOR_PROPERTY, principalName); } doc.setPropertyValue(DUBLINCORE_CONTRIBUTORS_PROPERTY, (Serializable) contributorsList); doc.setPropertyValue(DUBLINCORE_LAST_CONTRIBUTOR_PROPERTY, principalName); }); }
DublinCoreStorageServiceImpl extends DefaultComponent implements DublinCoreStorageService { @Override public void addContributor(DocumentModel doc, Event event) { NuxeoPrincipal principal = Objects.requireNonNull(event.getContext().getPrincipal()); String principalName = principal.getActingUser(); if (principal instanceof SystemPrincipal && SYSTEM_USERNAME.equals(principalName) && !ABOUT_TO_CREATE.equals(event.getName())) { return; } List<String> contributorsList = getSanitizedExistingContributors(doc); if (!contributorsList.contains(principalName)) { contributorsList.add(principalName); } Framework.doPrivileged(() -> { if (doc.getPropertyValue(DUBLINCORE_CREATOR_PROPERTY) == null) { doc.setPropertyValue(DUBLINCORE_CREATOR_PROPERTY, principalName); } doc.setPropertyValue(DUBLINCORE_CONTRIBUTORS_PROPERTY, (Serializable) contributorsList); doc.setPropertyValue(DUBLINCORE_LAST_CONTRIBUTOR_PROPERTY, principalName); }); } }
DublinCoreStorageServiceImpl extends DefaultComponent implements DublinCoreStorageService { @Override public void addContributor(DocumentModel doc, Event event) { NuxeoPrincipal principal = Objects.requireNonNull(event.getContext().getPrincipal()); String principalName = principal.getActingUser(); if (principal instanceof SystemPrincipal && SYSTEM_USERNAME.equals(principalName) && !ABOUT_TO_CREATE.equals(event.getName())) { return; } List<String> contributorsList = getSanitizedExistingContributors(doc); if (!contributorsList.contains(principalName)) { contributorsList.add(principalName); } Framework.doPrivileged(() -> { if (doc.getPropertyValue(DUBLINCORE_CREATOR_PROPERTY) == null) { doc.setPropertyValue(DUBLINCORE_CREATOR_PROPERTY, principalName); } doc.setPropertyValue(DUBLINCORE_CONTRIBUTORS_PROPERTY, (Serializable) contributorsList); doc.setPropertyValue(DUBLINCORE_LAST_CONTRIBUTOR_PROPERTY, principalName); }); }  }
DublinCoreStorageServiceImpl extends DefaultComponent implements DublinCoreStorageService { @Override public void addContributor(DocumentModel doc, Event event) { NuxeoPrincipal principal = Objects.requireNonNull(event.getContext().getPrincipal()); String principalName = principal.getActingUser(); if (principal instanceof SystemPrincipal && SYSTEM_USERNAME.equals(principalName) && !ABOUT_TO_CREATE.equals(event.getName())) { return; } List<String> contributorsList = getSanitizedExistingContributors(doc); if (!contributorsList.contains(principalName)) { contributorsList.add(principalName); } Framework.doPrivileged(() -> { if (doc.getPropertyValue(DUBLINCORE_CREATOR_PROPERTY) == null) { doc.setPropertyValue(DUBLINCORE_CREATOR_PROPERTY, principalName); } doc.setPropertyValue(DUBLINCORE_CONTRIBUTORS_PROPERTY, (Serializable) contributorsList); doc.setPropertyValue(DUBLINCORE_LAST_CONTRIBUTOR_PROPERTY, principalName); }); }  @Override void setCreationDate(DocumentModel doc, Calendar creationDate); @Override void setIssuedDate(DocumentModel doc, Calendar issuedDate); @Override void setModificationDate(DocumentModel doc, Calendar modificationDate); @Override void addContributor(DocumentModel doc, Event event); }
DublinCoreStorageServiceImpl extends DefaultComponent implements DublinCoreStorageService { @Override public void addContributor(DocumentModel doc, Event event) { NuxeoPrincipal principal = Objects.requireNonNull(event.getContext().getPrincipal()); String principalName = principal.getActingUser(); if (principal instanceof SystemPrincipal && SYSTEM_USERNAME.equals(principalName) && !ABOUT_TO_CREATE.equals(event.getName())) { return; } List<String> contributorsList = getSanitizedExistingContributors(doc); if (!contributorsList.contains(principalName)) { contributorsList.add(principalName); } Framework.doPrivileged(() -> { if (doc.getPropertyValue(DUBLINCORE_CREATOR_PROPERTY) == null) { doc.setPropertyValue(DUBLINCORE_CREATOR_PROPERTY, principalName); } doc.setPropertyValue(DUBLINCORE_CONTRIBUTORS_PROPERTY, (Serializable) contributorsList); doc.setPropertyValue(DUBLINCORE_LAST_CONTRIBUTOR_PROPERTY, principalName); }); }  @Override void setCreationDate(DocumentModel doc, Calendar creationDate); @Override void setIssuedDate(DocumentModel doc, Calendar issuedDate); @Override void setModificationDate(DocumentModel doc, Calendar modificationDate); @Override void addContributor(DocumentModel doc, Event event);  }