Skip to content

Commit

Permalink
partial fix
Browse files Browse the repository at this point in the history
  • Loading branch information
alexsilaghi committed Nov 21, 2024
1 parent c3bae15 commit 39ecece
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 51 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ public EntityPostCoordinationHistory saveNewSpecificationHistory(EntityPostCoord
return readWriteLock.executeWriteLock(() -> mongoTemplate.save(specificationHistory, POSTCOORDINATION_HISTORY_COLLECTION));
}


public void addCustomScalesRevision(String whoficEntityIri, ProjectId projectId, PostCoordinationCustomScalesRevision customScalesRevision) {
Query query = new Query();
query.addCriteria(Criteria.where(WHOFIC_ENTITY_IRI).is(whoficEntityIri)
Expand Down Expand Up @@ -138,26 +139,68 @@ public void deletePostCoordinationCustomScalesRevision(ChangeRequestId changeReq

Query query = new Query();
query.addCriteria(
Criteria.where(CHANGE_REQUEST_ID).is(changeRequestId)
.and(WHOFIC_ENTITY_IRI).is(entityIri)
Criteria.where(WHOFIC_ENTITY_IRI).is(entityIri)
.and(PROJECT_ID).is(projectId.value())
);
Update update = new Update().pull("postCoordinationCustomScalesRevisions", Query.query(Criteria.where("changeRequestId").is(changeRequestId)));
Update update = new Update().pull("postCoordinationCustomScalesRevisions",
new Document("changeRequestId._id", changeRequestId.id()));

readWriteLock.executeReadLock(() ->
Optional.of(mongoTemplate.updateFirst(query,update, EntityCustomScalesValuesHistory.class, CUSTOM_SCALE_REVISIONS ))
);
}

public void deletePostCoordinationSpecificationRevision(ChangeRequestId changeRequestId, ProjectId projectId, String entityIri) {

Query query = new Query();
query.addCriteria(
Criteria.where(CHANGE_REQUEST_ID).is(changeRequestId)
.and(WHOFIC_ENTITY_IRI).is(entityIri)
Criteria.where(WHOFIC_ENTITY_IRI).is(entityIri)
.and(PROJECT_ID).is(projectId.value())
);
Update update = new Update().pull("postCoordinationRevisions", Query.query(Criteria.where("changeRequestId").is(changeRequestId)));
Update update = new Update().pull("postCoordinationRevisions",
new Document("changeRequestId._id", changeRequestId.id()));

readWriteLock.executeReadLock(() -> {

UpdateResult updateResult = mongoTemplate.updateFirst(query,update, EntityPostCoordinationHistory.class, POSTCOORDINATION_HISTORY_COLLECTION);
System.out.println(updateResult);
return null;
}

);
}

public void commitPostCoordinationSpecificationRevision(ChangeRequestId changeRequestId, ProjectId projectId, String entityIri){
Query query = new Query(Criteria.where(WHOFIC_ENTITY_IRI)
.is(entityIri)
.and(PROJECT_ID).is(projectId.id())
.and("postCoordinationRevisions")
.elemMatch(
Criteria.where("changeRequestId._id").is(changeRequestId)
.and("commitStatus").is(CommitStatus.UNCOMMITTED.name())
)
);
Update update = new Update().set("postCoordinationRevisions.$.commitStatus", CommitStatus.COMMITTED.name());

readWriteLock.executeReadLock(() ->
Optional.of(mongoTemplate.updateFirst(query,update, EntityPostCoordinationHistory.class, POSTCOORDINATION_HISTORY_COLLECTION))
);
}

public void commitPostCoordinationCustomScalesRevision(ChangeRequestId changeRequestId, ProjectId projectId, String entityIri){
Query query = new Query(Criteria.where(WHOFIC_ENTITY_IRI).is(entityIri)
.and(PROJECT_ID).is(projectId.id())
.and("postCoordinationCustomScalesRevisions")
.elemMatch(
Criteria.where("changeRequestId._id").is(changeRequestId)
.and("commitStatus").is(CommitStatus.UNCOMMITTED.name())
)
);

Update update = new Update().set("postCoordinationCustomScalesRevisions.$.commitStatus", CommitStatus.COMMITTED.name());

readWriteLock.executeReadLock(() ->
Optional.of(mongoTemplate.updateFirst(query,update, EntityCustomScalesValuesHistory.class, CUSTOM_SCALE_REVISIONS ))
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ public void addCustomScaleRevision(WhoficCustomScalesValues newScales,
newRevisionsEventEmitter.emitNewRevisionsEvent(projectId, newScales.whoficEntityIri(), newRevision);
}
}, () -> {
var newHistory = createNewEntityCustomScalesHistory(newScales, projectId, userId);
var newHistory = createNewEntityCustomScalesHistory(newScales, projectId, userId, changeRequestId);
var savedHistory = repository.saveNewCustomScalesHistory(newHistory);
savedHistory.getPostCoordinationCustomScalesRevisions()
.stream()
Expand All @@ -238,10 +238,11 @@ public void addCustomScaleRevision(WhoficCustomScalesValues newScales,

private EntityCustomScalesValuesHistory createNewEntityCustomScalesHistory(WhoficCustomScalesValues newScales,
ProjectId projectId,
UserId userId) {
UserId userId,
ChangeRequestId changeRequestId) {
WhoficCustomScalesValues oldSpec = WhoficCustomScalesValues.create(newScales.whoficEntityIri(), Collections.emptyList());
Set<PostCoordinationCustomScalesValueEvent> events = SpecificationToEventsMapper.createScaleEventsFromDiff(oldSpec, newScales);
var revision = PostCoordinationCustomScalesRevision.create(userId, events);
var revision = PostCoordinationCustomScalesRevision.create(userId, events, changeRequestId);
return EntityCustomScalesValuesHistory.create(newScales.whoficEntityIri(), projectId.value(), List.of(revision));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,52 +26,13 @@ public RevisionCommitService(PostCoordinationRepository postCoordinationReposito

@Transactional
public void rollbackRevision(ChangeRequestId changeRequestId, ProjectId projectId, String entityIri) {
postCoordinationRepository.deletePostCoordinationSpecificationRevision(changeRequestId, projectId, entityIri);
postCoordinationRepository.deletePostCoordinationCustomScalesRevision(changeRequestId, projectId, entityIri);
postCoordinationRepository.deletePostCoordinationSpecificationRevision(changeRequestId, projectId, entityIri);
}


public void commitRevision(ChangeRequestId changeRequestId, ProjectId projectId, String entityIri) {
Optional<EntityPostCoordinationHistory> postCoordinationHistory = postCoordinationRepository.getExistingHistoryOrderedByRevision(entityIri, projectId);
try {
if (postCoordinationHistory.isPresent()) {
List<PostCoordinationSpecificationRevision> uncommittedSpecifications = postCoordinationHistory.get().getPostCoordinationRevisions()
.stream()
.filter(revision -> revision.changeRequestId() != null &&
revision.changeRequestId().equals(changeRequestId) &&
revision.commitStatus().equals(CommitStatus.UNCOMMITTED))
.toList();
postCoordinationHistory.get().getPostCoordinationRevisions().removeAll(uncommittedSpecifications);
postCoordinationHistory.get().getPostCoordinationRevisions().addAll(uncommittedSpecifications.stream()
.map(PostCoordinationSpecificationRevision::createCommittedClone).toList());
postCoordinationRepository.saveNewSpecificationHistory(postCoordinationHistory.get());
} else {
LOGGER.error("Error finding postcoordinationHistory for " + entityIri);
}
}catch (Exception e){
LOGGER.error("Error committing post coordinationHistory for " + entityIri, e);
}

try{
Optional<EntityCustomScalesValuesHistory> customScalesHistory = postCoordinationRepository.getExistingCustomScaleHistoryOrderedByRevision(entityIri, projectId);
if(customScalesHistory.isPresent()) {
List<PostCoordinationCustomScalesRevision> uncommittedSpecifications = customScalesHistory.get().getPostCoordinationCustomScalesRevisions()
.stream()
.filter(revision -> revision.changeRequestId() != null &&
revision.changeRequestId().equals(changeRequestId) &&
revision.commitStatus().equals(CommitStatus.UNCOMMITTED))
.toList();
customScalesHistory.get().getPostCoordinationCustomScalesRevisions().removeAll(uncommittedSpecifications);
customScalesHistory.get().getPostCoordinationCustomScalesRevisions().addAll(uncommittedSpecifications.stream()
.map(PostCoordinationCustomScalesRevision::createCommittedClone).toList());
postCoordinationRepository.saveNewCustomScalesHistory(customScalesHistory.get());
} else {
LOGGER.error("Error finding postCoordinationCustomScales for " + entityIri);
}

}catch (Exception e){
LOGGER.error("Error committing postCoordinationCustomScales for " + entityIri, e);

}
postCoordinationRepository.commitPostCoordinationSpecificationRevision(changeRequestId, projectId, entityIri);
postCoordinationRepository.commitPostCoordinationCustomScalesRevision(changeRequestId, projectId, entityIri);
}
}
2 changes: 2 additions & 0 deletions src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ webprotege:
requestqueue: webprotege-postcoordination-service-queue
responsequeue: webprotege-postcoordination-service-response-queue
timeout: 60000
eventsqueue: webprotege-postcoordination-events-queue
event-subscribe: true
readWriteLock:
timeoutInMillies: 1000
maxRetries: 5

0 comments on commit 39ecece

Please sign in to comment.