Delete does not work as expexted in a JavaEE transaction

cancel
Showing results for 
Search instead for 
Did you mean: 
Highlighted
Member II

Delete does not work as expexted in a JavaEE transaction

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:

@Override
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$
   document.delete(allVersions);
}

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();
   person.setProfilePicture(null);
   em.remove(documentSubmission);
   em.flush();
   documentManager.deleteAvatar(documentId);
}

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?

2 Replies
Highlighted
Professional

Re: Delete does not work as expexted in a JavaEE transaction

This comment does not directly address your problem, but you should know that this line is asking for trouble:

Document document = (Document) session
      .getObject(documentId + ((null == version || version.equals("")) ? "" : ";" + version));

CMIS object ID's are defined by the spec to be opaque. Just because that string at the end looks like a version ID does not mean you should interpret it that way.

Alfresco could decide to change their object ID format at any time with no notice. Also, this wouldn't work with other repositories, which is one of the points of CMIS.

Highlighted
Member II

Re: Delete does not work as expexted in a JavaEE transaction

Thank you very much Jeff for your answer, i understand what you are saying and we are planning to fix it, any idea about the case above? 

Inside a transaction we do stuff with the db and send a delete to alfresco, two times we have the case of interacting successfully with the db but the document stays in alfresco.