@Override public void deleteDocuments(final boolean allVersions, final DocumentUUID... documentUUIDs) throws DocumentNotFoundException { final DocumentationManager manager = EnvTool.getDocumentationManager(); final Querier queriers = EnvTool.getAllQueriers(); if (documentUUIDs != null) { org.ow2.bonita.services.Document doc; ProcessInstanceUUID processInstanceUUID; for (final DocumentUUID documentUUID : documentUUIDs) { doc = manager.getDocument(documentUUID.getValue()); processInstanceUUID = doc.getProcessInstanceUUID(); manager.deleteDocument(documentUUID.getValue(), allVersions); if (processInstanceUUID != null) { final InternalProcessInstance instance = queriers.getProcessInstance(processInstanceUUID); if (instance != null) { final int nbOfAttachments = instance.getNbOfAttachments() - 1; instance.setNbOfAttachments(nbOfAttachments); } else { LOG.info("When deleting documents, cannot update the process instance because of its deletion"); } } } } } }
@Override public void removeAttachment(final ProcessInstanceUUID instanceUUID, final String name) throws InstanceNotFoundException { FacadeUtil.checkArgsNotNull(instanceUUID, name); final InternalProcessInstance instance = EnvTool.getJournalQueriers().getProcessInstance(instanceUUID); if (instance == null) { throw new InstanceNotFoundException("bai_RAPII_1", instanceUUID); } if (instance.getNbOfAttachments() <= 0) { throw new BonitaRuntimeException(new DocumentNotFoundException(name)); } final DocumentationManager manager = EnvTool.getDocumentationManager(); final List<org.ow2.bonita.services.Document> documents = DocumentService.getDocuments(manager, instanceUUID, name); if (!documents.isEmpty()) { final org.ow2.bonita.services.Document document = documents.get(0); try { manager.deleteDocument(document.getId(), true); // Keep mapping with number of attachments. instance.setNbOfAttachments(instance.getNbOfAttachments() - 1); } catch (final DocumentNotFoundException e) { throw new BonitaRuntimeException(e); } } }