waveId = ApiIdSerializer.instance().deserialiseWaveId(
OperationUtil.<String>getRequiredParameter(operation, ParamsProperty.WAVE_ID));
waveletId = ApiIdSerializer.instance().deserialiseWaveletId(
OperationUtil.<String>getRequiredParameter(operation, ParamsProperty.WAVELET_ID));
} catch (InvalidIdException ex) {
throw new InvalidRequestException("Invalid id", operation, ex);
}
waveId = WaveId.of(waveDomain, waveId.getId());
waveletId = WaveletId.of(waveDomain, waveletId.getId());
List<byte[]> history =
OperationUtil.getRequiredParameter(operation, ParamsProperty.RAW_DELTAS);
WaveletName waveletName = WaveletName.of(waveId, waveletId);
long importedFromVersion = -1;
if (!history.isEmpty()) {
CommittedWaveletSnapshot waveletSnapshot;
try {
waveletSnapshot = waveletProvider.getSnapshot(waveletName);
} catch (WaveServerException ex) {
LOG.info("Get wavelet snapshot", ex);
context.constructErrorResponse(operation, ex.toString());
return;
}
for (byte[] deltaBytes : history) {
ProtocolWaveletDelta delta;
try {
delta = ProtocolWaveletDelta.parseFrom(deltaBytes);
} catch (InvalidProtocolBufferException ex) {
throw new InvalidRequestException("Parse delta", operation, ex);
}
long currentVersion = 0;
if (waveletSnapshot != null) {
currentVersion = waveletSnapshot.snapshot.getVersion();
}
if (currentVersion == delta.getHashedVersion().getVersion()) {
if (importedFromVersion == -1) {
importedFromVersion = currentVersion;
}
ProtocolWaveletDelta newDelta;
try {
newDelta = setVersionHash(delta, waveletSnapshot, waveletName);
} catch (InvalidParticipantAddress ex) {
throw new InvalidRequestException("Convert delta", operation, ex);
}
final StringBuffer error = new StringBuffer();
waveletProvider.submitRequest(waveletName, newDelta,
new WaveletProvider.SubmitRequestListener() {