@Test public void shouldRemovePrefixContributorsWhenAdding() { DocumentModel doc = session.createDocumentModel("/", "file", "File"); doc.setPropertyValue("dc:creator", "Original Creator"); doc.setPropertyValue("dc:lastContributor", "Original Creator"); doc.setPropertyValue("dc:contributors", new String[] { "Original Creator", "user:Administrator", "user:Other User" }); Map<String, Object> originalProperties = new HashMap<>(doc.getProperties("dublincore")); Set<String> expectedChangedProperties = new HashSet<>(); expectedChangedProperties.add("dc:lastContributor"); expectedChangedProperties.add("dc:contributors"); Event event = getEventFromDocumentContext(BEFORE_DOC_UPDATE, session, session.getPrincipal()); storageService.addContributor(doc, event); assertDocumentPropertiesChanges(doc, originalProperties, expectedChangedProperties); String principalName = session.getPrincipal().getName(); assertEquals(principalName, doc.getPropertyValue("dc:lastContributor")); List<String> contributors = Arrays.asList((String[]) doc.getPropertyValue("dc:contributors")); assertEquals(3, contributors.size()); assertTrue(contributors.contains("Original Creator")); assertTrue(contributors.contains("Other User")); assertTrue(contributors.contains(principalName)); }
@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);  }