use of me.retrodaredevil.solarthing.database.exception.UnauthorizedSolarThingDatabaseException in project solarthing by wildmountainfarms.
the class CouchDbAlterDatabase method delete.
@Override
public void delete(String documentId, UpdateToken updateToken) throws SolarThingDatabaseException {
RevisionUpdateToken revisionUpdateToken = CouchDbSolarThingDatabase.checkUpdateToken(updateToken);
String revision = revisionUpdateToken.getRevision();
try {
database.deleteDocument(documentId, revision);
} catch (CouchDbUnauthorizedException e) {
throw new UnauthorizedSolarThingDatabaseException(e);
} catch (CouchDbUpdateConflictException e) {
throw new UpdateConflictSolarThingDatabaseException("Update conflict on delete. Must not be latest revision. documentId: " + documentId + " revision: " + revision, e);
} catch (CouchDbNotFoundException e) {
throw new NotFoundSolarThingDatabaseException("(Not found) Could not delete documentId: " + documentId + " revision: " + revision, e);
} catch (CouchDbException e) {
throw new SolarThingDatabaseException("Could not delete documentId: " + documentId + " revision: " + revision, e);
}
}
use of me.retrodaredevil.solarthing.database.exception.UnauthorizedSolarThingDatabaseException in project solarthing by wildmountainfarms.
the class SecurityPacketReceiver method uploadSecurityEventPacket.
private void uploadSecurityEventPacket(SecurityEventPacket packet) {
Instant now = Instant.now();
String id = "security-event-status-" + fragmentId + "-" + packet.getRequestDocumentId();
PacketCollection packetCollection = PacketCollections.create(now, Arrays.asList(packet, InstanceFragmentIndicatorPackets.create(fragmentId), InstanceSourcePackets.create(sourceId)), id);
executorService.execute(() -> {
for (int tryIndex = 0; tryIndex < 3; tryIndex++) {
try {
eventDatabase.uploadPacketCollection(packetCollection, null);
break;
} catch (UpdateConflictSolarThingDatabaseException e) {
LOGGER.warn("Got update conflict exception for id: " + id, e);
// We will assume we have already uploaded this packet to the database
break;
} catch (UnauthorizedSolarThingDatabaseException e) {
LOGGER.warn("Not authorized to upload to events database", e);
break;
} catch (SolarThingDatabaseException e) {
LOGGER.error("Could not upload security event packet. tryIndex: " + tryIndex + " id: " + id, e);
}
try {
Thread.sleep((tryIndex + 1) * 100);
} catch (InterruptedException e) {
LOGGER.error("Was interrupted", e);
Thread.currentThread().interrupt();
}
}
});
}
Aggregations