use of me.retrodaredevil.couchdbjava.response.DocumentData in project solarthing by wildmountainfarms.
the class CouchDbSetupMain method createUserIfNotExists.
private void createUserIfNotExists(String username, SolarThingDatabaseType.UserType userType) throws CouchDbException {
CouchDbDatabase usersDatabase = instance.getUsersDatabase();
String documentId = "org.couchdb.user:" + username;
DocumentData userDocumentData = null;
try {
userDocumentData = usersDatabase.getDocument(documentId);
} catch (CouchDbNotFoundException ignored) {
}
final UserEntry user;
if (userDocumentData != null) {
try {
user = CouchDbJacksonUtil.readValue(MAPPER, userDocumentData.getJsonData(), UserEntry.class);
} catch (JsonProcessingException e) {
throw new RuntimeException("Could not parse user document data. Please report this bug", e);
}
} else {
user = null;
}
if (user != null) {
out.println("User: " + username + " exists! Continuing.");
} else {
out.println("Please enter a password for '" + username + "'.");
String password = prompt.promptUserPassword(userType);
final JsonData jsonData;
try {
jsonData = new StringJsonData(MAPPER.writeValueAsString(new UserEntry(username, password)));
} catch (JsonProcessingException e) {
throw new RuntimeException("Couldn't serialize json! Report this!", e);
}
usersDatabase.createIfNotExists();
usersDatabase.putDocument(documentId, jsonData);
}
}
use of me.retrodaredevil.couchdbjava.response.DocumentData in project solarthing by wildmountainfarms.
the class CouchDbMillisDatabase method getPacketCollection.
@Override
public VersionedPacket<StoredPacketGroup> getPacketCollection(String documentId) throws SolarThingDatabaseException {
final DocumentData documentData;
try {
documentData = database.getDocument(documentId);
} catch (CouchDbException e) {
throw ExceptionUtil.createFromCouchDbException("Could not get packet collection with document ID: " + documentId, e);
}
JsonData jsonData = documentData.getJsonData();
return jsonDataToStoredPacketGroup(jsonData);
}
use of me.retrodaredevil.couchdbjava.response.DocumentData in project solarthing by wildmountainfarms.
the class CouchDbSolarThingDatabase method queryMetadata.
@Override
@Nullable
public VersionedPacket<RootMetaPacket> queryMetadata(UpdateToken updateToken) throws SolarThingDatabaseException {
DocumentData data = queryDocument(closedDatabase, RootMetaPacket.DOCUMENT_ID, updateToken);
if (data == null) {
return null;
}
JsonData jsonData = data.getJsonData();
try {
RootMetaPacket packet = CouchDbJacksonUtil.readValue(metaObjectMapper, jsonData, RootMetaPacket.class);
return new VersionedPacket<>(packet, new RevisionUpdateToken(data.getRevision()));
} catch (JsonProcessingException e) {
throw new SolarThingDatabaseException("Invalid meta! Failed to parse!", e);
}
}
use of me.retrodaredevil.couchdbjava.response.DocumentData in project solarthing by wildmountainfarms.
the class CouchDbSolarThingDatabase method queryAuthorized.
@Override
@Nullable
public VersionedPacket<AuthorizationPacket> queryAuthorized(UpdateToken updateToken) throws SolarThingDatabaseException {
DocumentData data = queryDocument(closedDatabase, AuthorizationPacket.DOCUMENT_ID, updateToken);
if (data == null) {
return null;
}
JsonData jsonData = data.getJsonData();
try {
AuthorizationPacket packet = CouchDbJacksonUtil.readValue(simpleObjectMapper, jsonData, AuthorizationPacket.class);
return new VersionedPacket<>(packet, new RevisionUpdateToken(data.getRevision()));
} catch (JsonProcessingException e) {
throw new SolarThingDatabaseException("Invalid authorization packet! Failed to parse!", e);
}
}
Aggregations