private void deleteDocuments(final List<DocumentDescriptor> documentDescriptors) throws DocumentNotFoundException { for (final DocumentDescriptor documentDesc : documentDescriptors) { deleteDocuments(documentDesc); } }
@Override public void clear() throws DocumentNotFoundException { List<DocumentDescriptor> documentDescriptors = Collections.emptyList(); final DocumentDbSession dbSession = getDbSession(); do { // as the document will be deleted we must keep the same value (zero) for // the start index documentDescriptors = dbSession.getDocumentDescriptors(0, MAX_RESULTS); deleteDocuments(documentDescriptors); } while (!documentDescriptors.isEmpty()); }
@Override public void deleteDocuments(final ProcessDefinitionUUID definitionUUID) throws DocumentNotFoundException { List<DocumentDescriptor> documentDescriptors = Collections.emptyList(); do { documentDescriptors = getDbSession().getDocumentDescriptors(definitionUUID, 0, MAX_RESULTS); deleteDocuments(documentDescriptors); } while (!documentDescriptors.isEmpty()); }
@Override public void deleteDocument(final String documentId, final boolean allVersions) throws DocumentNotFoundException { final DocumentVersion documentVersion = getDbSession().getDocumentVersion(Long.valueOf(documentId)); final DocumentDescriptor documentDescriptor = getDbSession().getDocumentDescriptor( Long.valueOf(documentVersion.getVersionSeriesId())); if (allVersions) { // delete all versions from descriptor deleteDocuments(documentDescriptor); } else { // delete version deleteVersionAndContent(documentVersion); final List<DocumentVersion> documentVersions = getDbSession().getDocumentVersions(documentDescriptor.getId()); if (documentVersions.isEmpty()) { // if it was the last version also delete the descriptor getDbSession().delete(documentDescriptor); } else if (documentDescriptor.getLastVersionId() == documentVersion.getId()) { // if there are other version and the last version was deleted update descriptor documentDescriptor.setLastVersionId(documentVersions.get(0).getId()); } } }