Fixed `unlockAndPatch` method
This commit is contained in:
parent
04a86e0280
commit
c273a2db2c
|
@ -184,28 +184,35 @@ public class ProfiledMongoManager extends MongoManager implements MongoManagerI<
|
|||
protected Project unlockAndPatch(Project proj) throws InvalidLockException, ProjectNotFoundException,
|
||||
JsonProcessingException, InvalidUserRoleException, UnauthorizedAccess {
|
||||
log.info("Unlocking for patching {} lock is {} ", proj.getId(), proj.getLock());
|
||||
|
||||
// find one and update
|
||||
Lock oldLock = proj.getLock();
|
||||
proj.setLock(null);
|
||||
|
||||
Document filter = new Document(mongoIDFieldName(), asId(proj.getId())).append(Project.LOCK + "." + Lock.ID,
|
||||
oldLock.getId());
|
||||
|
||||
Document setUpdatedDocument = new Document("$set", new Document(Project.THE_DOCUMENT, proj.getTheDocument()));
|
||||
|
||||
log.info("Filter document is {} ", filter.toJson());
|
||||
log.info("$set is {} ", setUpdatedDocument);
|
||||
|
||||
Object obj = getCollection().findOneAndUpdate(
|
||||
// filter by id and missing lock
|
||||
filter,
|
||||
// update lock info
|
||||
asDocumentWithId(proj), new FindOneAndUpdateOptions().returnDocument(ReturnDocument.AFTER));
|
||||
setUpdatedDocument,
|
||||
new FindOneAndUpdateOptions().returnDocument(ReturnDocument.AFTER));
|
||||
|
||||
if (obj == null) {
|
||||
// can-t unlock, check cause
|
||||
Project p = getByID(proj.getId());
|
||||
throw new InvalidLockException(
|
||||
"Found lock for " + p.getId() + " is " + p.getLock() + ", expected is " + oldLock);
|
||||
"Found lock for " + proj.getId() + " is " + proj.getLock() + ", expected is " + oldLock);
|
||||
}
|
||||
return Serialization.convert(obj, Project.class);
|
||||
|
||||
//I could use Serialization.convert(obj, Project.class), but to be sure I'm reading again the project by
|
||||
proj = getByID(proj.getId());
|
||||
|
||||
proj = unlock(proj);
|
||||
return proj;
|
||||
}
|
||||
|
||||
protected Project unlock(Project proj)
|
||||
|
|
Loading…
Reference in New Issue