use of org.jboss.pnc.bpm.MissingInternalReferenceException in project pnc by project-ncl.
the class BuildResultPushManager method complete.
public Long complete(Base32LongID buildRecordId, BuildRecordPushResult buildRecordPushResult) {
// accept only listed elements otherwise a new request might be wrongly completed from response of an older one
// get context for validation
InProgress.Context pushContext = inProgress.get(buildRecordId);
if (pushContext == null) {
throw new MissingInternalReferenceException("Did not find referenced element.");
}
Long expectedPushResultId = BuildPushResultMapper.idMapper.toEntity(pushContext.getPushResultId());
// if the result id is set it must match the id generated when the remote operation has been triggered
if (buildRecordPushResult.getId() != null && !buildRecordPushResult.getId().equals(expectedPushResultId)) {
throw new InvalidReferenceException("Unexpected result id: " + buildRecordPushResult.getId());
}
// get and remove the context atomically
pushContext = inProgress.remove(buildRecordId);
if (pushContext == null) {
throw new MissingInternalReferenceException("Referenced element has gone.");
}
buildRecordPushResult.setId(expectedPushResultId);
buildRecordPushResult.setTagPrefix(pushContext.getTagPrefix());
BuildRecordPushResult saved = buildRecordPushResultRepository.save(buildRecordPushResult);
buildPushResultEvent.fire(mapper.toDTO(saved));
return saved.getId();
}
Aggregations