AnsweredAssumed Answered

Delete does not work as expexted in a JavaEE transaction

Question asked by paner on Dec 19, 2018
Latest reply on Dec 21, 2018 by paner

We have implemented a library for interacting Alfresco with CMIS 1.1 library. We implemented all add/update/delete... methods. In production two times in a year we had the case where a delete didn't work as expected.
Here is the delete method of the library:

public void deleteById(String documentId, boolean allVersions, String version, ConnectionParameter parameter) {
   LoginController loginController = new LoginController();
   Session session = loginController.login(parameter);
   Document document = (Document) session
      .getObject(documentId + ((null == version || version.equals("")) ? "" : ";" + version)); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$

And is called from our main program like this:

public void deleteAvatar(String personId) {
   final Person person = em.find(Person.class, personId);
   final DocumentSubmission documentSubmission = person.getProfilePicture();
   final String documentId = documentSubmission.getManagedCopy();

The business logic we need, is to have a database table called DocumentSubmission where the person id is saved with other information of the alfresco document along with Alfresco document id.
Also in person database table we have a column profilePicture where references each document submission in DocumentSumbission table.

So in the FE when a Person card page is opened a check is made, if person has an id of profilepicture then it tries to fetch the document in the DocumentSumbission table with the Alfresco id.
When a delete is made the DocumentSubmission row is deleted completly, the persons profilePicture column is set to null and delete is send to alfresco to delete the document with that id.

But we have a case where DocumentSubmission row is delete and the profilePicture column is set to null but the document stays in alfresco. The document name is the person's id with the file extension, so when the user is trying to add a new photo the file already exists in alfresco and we throw an error that the file already exists, which is wrong.

We use JavaEE.

Is there a case where the Alfresco delete wont delete the file and no exception is thrown? Do you see something wrong with this approach?