@Override public Document createDocument(final String name, final ProcessDefinitionUUID definitionUUID, final ProcessInstanceUUID instanceUUID) throws DocumentationCreationException, DocumentAlreadyExistsException { return createDocument(name, definitionUUID, instanceUUID, null, null, null); }
@Override public Document createVersion(final String documentId, final boolean isMajorVersion) throws DocumentationCreationException { return createVersion(documentId, isMajorVersion, null, "application/octet-stream", null); }
private void deleteDocuments(final List<DocumentDescriptor> documentDescriptors) throws DocumentNotFoundException { for (final DocumentDescriptor documentDesc : documentDescriptors) { deleteDocuments(documentDesc); } }
private void deleteDocuments(final DocumentDescriptor documentDesc) throws DocumentNotFoundException { deleteVersions(documentDesc); deleteMappingDescriptors(documentDesc); getDbSession().delete(documentDesc); }
@Override public Document createVersion(final String documentId, final boolean isMajorVersion, final String fileName, final String mimeType, final byte[] content, final String author, final Date creationDate, final Date lastModificationDate) throws DocumentationCreationException { final DocumentVersion lastVersion = getDbSession().getDocumentVersion(Long.valueOf(documentId)); final Long documentDescriptorId = Long.valueOf(lastVersion.getVersionSeriesId()); // ensure that exists a lock entry for the given descriptor id ensureHasLockEntry(documentDescriptorId); Document document = null; synchronized (documentsLock.get(documentDescriptorId)) { final DocumentDescriptor documentDescriptor = getDbSession().getDocumentDescriptor(documentDescriptorId); document = createDocumentVersionUsingDescriptor(fileName, mimeType, content, isMajorVersion, author, creationDate, lastModificationDate, documentDescriptor); } // remove the lock entry if it isn't used anymore removeLockEntryIfPossible(documentDescriptorId); return document; }
@Override public List<Document> getVersionsOfDocument(final String documentId) throws DocumentNotFoundException { final DocumentVersion currentDocumentVersion = getDbSession().getDocumentVersion(Long.valueOf(documentId)); final DocumentDescriptor documentDescriptor = getDbSession().getDocumentDescriptor( Long.valueOf(currentDocumentVersion.getVersionSeriesId())); final List<DocumentVersion> documentVersions = getDbSession().getDocumentVersions(documentDescriptor.getId()); final List<Document> documents = new ArrayList<Document>(documentVersions.size()); for (final DocumentVersion documentVersion : documentVersions) { documents.add(toDocument(documentDescriptor, documentVersion)); } return documents; }
@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()); } } }
@Override public List<Document> getDocuments(final ProcessInstanceUUID instanceUUID, final String documentName, final int fromResult, final int maxResults) { return getDbSession().getDocuments(instanceUUID, documentName, fromResult, maxResults); }
@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()); }
private void deleteVersions(final DocumentDescriptor documentDesc) throws DocumentNotFoundException { List<DocumentVersion> documentVersions = Collections.emptyList(); do { documentVersions = getDbSession().getDocumentVersions(0, MAX_RESULTS, documentDesc.getId()); for (final DocumentVersion documentVersion : documentVersions) { deleteVersionAndContent(documentVersion); } } while (!documentVersions.isEmpty()); }
@Override public SearchResult search(final DocumentSearchBuilder builder, final int fromResult, final int maxResults) { final List<Document> documents = getDbSession().searchDocuments(builder, fromResult, maxResults); final long numberOfDocuments = getDbSession().getNumberOfDocuments(builder); return new SearchResult(documents, toInt(numberOfDocuments)); }
private Document createDocument(final String name, final ProcessDefinitionUUID definitionUUID, final ProcessInstanceUUID instanceUUID, final String fileName, final String contentMimeType, final byte[] fileContent, final boolean metaDocument, final String author, final Date creationDate, final Date lastModificationDate) throws DocumentationCreationException, DocumentAlreadyExistsException { long nbOfDocuments = 0; if (instanceUUID != null) { nbOfDocuments = getDbSession().hasDocuments(instanceUUID, name, metaDocument); } else { nbOfDocuments = getDbSession().hasDocuments(definitionUUID, name, metaDocument); } if (nbOfDocuments > 0) { throw new DocumentAlreadyExistsException("DAEE", name); } final DocumentDescriptorImpl documentDescriptorImpl = new DocumentDescriptorImpl(name, definitionUUID, instanceUUID, metaDocument, 0); getDbSession().save(documentDescriptorImpl); // add mapping final DocumentDescriptorMappingImpl docDescMapping = new DocumentDescriptorMappingImpl( documentDescriptorImpl.getId(), definitionUUID, instanceUUID); getDbSession().save(docDescMapping); return createDocumentVersionUsingDescriptor(fileName, contentMimeType, fileContent, true, author, creationDate, lastModificationDate, documentDescriptorImpl); }
@Override public Document getDocument(final String documentId) throws DocumentNotFoundException { final DocumentVersion documentVersion = getDbSession().getDocumentVersion(Long.valueOf(documentId)); if (documentVersion == null) { throw new DocumentNotFoundException(documentId); } final DocumentDescriptor documentDescriptor = getDbSession().getDocumentDescriptor( Long.valueOf(documentVersion.getVersionSeriesId())); return toDocument(documentDescriptor, documentVersion); }
@Override public List<Document> getDocuments(final ProcessDefinitionUUID processDefUUID, final String documentName, final int fromResult, final int maxResults) { return getDbSession().getDocuments(processDefUUID, documentName, fromResult, maxResults); }
@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()); }
private Document createDocumentVersionUsingDescriptor(final String fileName, final String contentMimeType, final byte[] fileContent, final boolean isMajorVersion, final String author, final Date creationDate, final Date lastModificationDate, final DocumentDescriptor documentDescriptor) throws DocumentationCreationException { final long length = fileContent == null ? 0 : fileContent.length; final long versionLabel = documentDescriptor.getLastVersionLabel() + 1; final DocumentVersionImpl documentVersionImpl = new DocumentVersionImpl(author, creationDate, lastModificationDate, isMajorVersion, documentDescriptor.getId(), fileName, contentMimeType, length, versionLabel); documentStorageService.storeDocumentContent(documentVersionImpl, fileContent); getDbSession().save(documentVersionImpl); documentDescriptor.setLastVersionId(Long.valueOf(documentVersionImpl.getId())); documentDescriptor.setLastVersionLabel(versionLabel); return toDocument(documentDescriptor, documentVersionImpl); }
@Override public List<Document> getDocumentsOfProcessDefinitionWithoutInstances(final ProcessDefinitionUUID processDefUUID, final int fromResult, final int maxResults) { return getDbSession().getDocumentsOfProcessDefinitionWithoutInstances(processDefUUID, fromResult, maxResults); }
@Override public Document createDocument(final String name, final ProcessDefinitionUUID definitionUUID, final ProcessInstanceUUID instanceUUID, final String fileName, final String contentMimeType, final byte[] fileContent) throws DocumentationCreationException, DocumentAlreadyExistsException { return createDocument(name, definitionUUID, instanceUUID, fileName, contentMimeType, fileContent, false); }
@Override public Document createVersion(final String documentId, final boolean isMajorVersion, final String fileName, final String mimeType, final byte[] content) throws DocumentationCreationException { final Date now = new Date(); return createVersion(documentId, isMajorVersion, fileName, mimeType, content, EnvTool.getUserId(), now, now); }
@Override public long getNbOfDocuments(final ProcessInstanceUUID instanceUUID, final String documentName) { return getDbSession().getNbOfDocuments(instanceUUID, documentName); }