use of edu.uiuc.ncsa.security.storage.sql.internals.ColumnMap in project OA4MP by ncsa.
the class ClientServerTest method testCreate.
public void testCreate(CMTestStoreProvider tp2) throws Exception {
// only needs an admin client and map.
CC cc = setupClients(tp2);
OA2ClientConverter converter = getClientConverter(tp2);
ColumnMap values = new ColumnMap();
converter.toMap(cc.client, values);
tp2.getClientStore().remove(cc.client.getIdentifier());
assert !tp2.getClientStore().containsKey(cc.client.getIdentifier());
// remove the identifier and create it
OA2ClientKeys clientKeys = getClientKeys(tp2);
values.remove(clientKeys.identifier());
values.remove(clientKeys.creationTS());
JSONObject json = new JSONObject();
json.putAll(values);
CreateRequest req = RequestFactory.createRequest(cc.adminClient, new TypeClient(), new ActionCreate(), null, json);
ClientServer server = new ClientServer(tp2.getCOSE());
CreateResponse resp = (CreateResponse) server.process(req);
OA2Client newClient = resp.getClient();
assert tp2.getClientStore().containsKey(newClient.getIdentifier());
// quick and dirty check
OA2Client oldClient = (OA2Client) cc.client;
oldClient.setIdentifier(newClient.getIdentifier());
oldClient.setSecret(newClient.getSecret());
assert oldClient.equals(newClient);
}
use of edu.uiuc.ncsa.security.storage.sql.internals.ColumnMap in project OA4MP by ncsa.
the class SQLAssetStore method getByToken.
@Override
public Asset getByToken(Identifier token) {
if (token == null) {
return null;
}
Connection c = getConnection();
Asset t = null;
try {
PreparedStatement stmt = c.prepareStatement(getAST().getByTokenStatement());
stmt.setString(1, token.toString());
stmt.executeQuery();
ResultSet rs = stmt.getResultSet();
// Now we have to pull in all the values.
if (!rs.next()) {
rs.close();
stmt.close();
// returning a null fulfills contract for this being a map.
return null;
}
ColumnMap map = rsToMap(rs);
rs.close();
stmt.close();
t = create();
populate(map, t);
} catch (SQLException e) {
destroyConnection(c);
throw new GeneralException("Error getting object with identifier \"" + token + "\"", e);
} finally {
releaseConnection(c);
}
return t;
}
Aggregations