/** * @since 8.4 */ private void checkDeleteGuards() { List<DirectoryDeleteConstraint> deleteConstraints = directory.getDirectoryDeleteConstraints(); DirectoryService directoryService = Framework.getService(DirectoryService.class); if (deleteConstraints != null && !deleteConstraints.isEmpty()) { for (DirectoryDeleteConstraint deleteConstraint : deleteConstraints) { if (!deleteConstraint.canDelete(directoryService, entryId)) { throw new NuxeoException("This entry is referenced in another vocabulary.", SC_BAD_REQUEST); } } } }
public DirectoryDeleteConstraint getDeleteConstraint() { try { DirectoryDeleteConstraint instance = klass.newInstance(); if (properties != null) { instance.setProperties(properties); } return instance; } catch (InstantiationException e) { throw new DirectoryException(e); } catch (IllegalAccessException e) { throw new DirectoryException(e); } }
/** * Checks that there are no constraints for deleting the given entry id. * * @since 8.4 */ public void checkDeleteConstraints(String entryId) { List<DirectoryDeleteConstraint> deleteConstraints = directory.getDirectoryDeleteConstraints(); DirectoryService directoryService = Framework.getService(DirectoryService.class); if (deleteConstraints != null && !deleteConstraints.isEmpty()) { for (DirectoryDeleteConstraint deleteConstraint : deleteConstraints) { if (!deleteConstraint.canDelete(directoryService, entryId)) { throw new DirectoryDeleteConstraintException("This entry is referenced in another vocabulary."); } } } }
public void deleteDirectoryEntry(String entryId) { String dirName = currentDirectoryInfo.getName(); List<DirectoryDeleteConstraint> deleteConstraints = currentDirectoryInfo.getDeleteConstraints(); if (deleteConstraints != null && !deleteConstraints.isEmpty()) { for (DirectoryDeleteConstraint deleteConstraint : deleteConstraints) { if (!deleteConstraint.canDelete(dirService, entryId)) { facesMessages.add(StatusMessage.Severity.ERROR, messages.get("feedback.directory.deleteEntry.constraintError")); return; } } } try (Session dirSession = dirService.open(dirName)) { try { dirSession.deleteEntry(entryId); // invalidate directory entries list currentDirectoryEntries = null; Events.instance().raiseEvent(EventNames.DIRECTORY_CHANGED, dirName); facesMessages.add(StatusMessage.Severity.INFO, messages.get("vocabulary.entry.deleted")); } catch (DirectoryDeleteConstraintException e) { facesMessages.add(StatusMessage.Severity.ERROR, messages.get("feedback.directory.deleteEntry.constraintError")); } } }