- public Map<String, Object> createTable(
- @ApiParam(value = "Major Version",
- required = true) @PathParam("version") String version,
- @ApiParam(value = "Minor Version",
- required = false) @HeaderParam("X-minorVersion") String minorVersion,
- @ApiParam(value = "Patch Version",
- required = false) @HeaderParam("X-patchVersion") String patchVersion,
- @ApiParam(value = "AID", required = true) @HeaderParam("aid") String aid,
- @ApiParam(value = "Application namespace",
- required = true) @HeaderParam("ns") String ns,
- @ApiParam(value = "userId",
- required = true) @HeaderParam("userId") String userId,
- @ApiParam(value = "Password",
- required = true) @HeaderParam("password") String password,
- JsonTable tableObj,
- @ApiParam(value = "Keyspace Name",
- required = true) @PathParam("keyspace") String keyspace,
- @ApiParam(value = "Table Name",
- required = true) @PathParam("tablename") String tablename,
- @Context HttpServletResponse response) throws Exception {
-
- Map<String, Object> authMap = MusicCore.autheticateUser(ns, userId, password, keyspace,
- aid, "createTable");
- response.addHeader(xLatestVersion, MusicUtil.getVersion());
- if (authMap.containsKey("aid"))
- authMap.remove("aid");
- if (!authMap.isEmpty()) {
- return new JsonResponse(ResultType.FAILURE).setError(String.valueOf(authMap.get("Exception"))).toMap();
- }
- String consistency = MusicUtil.EVENTUAL;
- // for now this needs only eventual consistency
- PreparedQueryObject queryObject = new PreparedQueryObject();
- // first read the information about the table fields
- Map<String, String> fields = tableObj.getFields();
- StringBuilder fieldsString = new StringBuilder("(vector_ts text,");
- int counter = 0;
- String primaryKey;
- for (Map.Entry<String, String> entry : fields.entrySet()) {
-
- if (entry.getKey().equals("PRIMARY KEY")) {
- if(! entry.getValue().contains("("))
- primaryKey = entry.getValue();
- else {
- primaryKey = entry.getValue().substring(entry.getValue().indexOf('(') + 1);
- primaryKey = primaryKey.substring(0, primaryKey.indexOf(')'));
- }
- fieldsString.append("" + entry.getKey() + " (" + primaryKey + ")");
- } else
- fieldsString.append("" + entry.getKey() + " " + entry.getValue() + "");
- if (counter == fields.size() - 1)
- fieldsString.append(")");
- else
- fieldsString.append(",");
- counter = counter + 1;
- }
- // information about the name-value style properties
- Map<String, Object> propertiesMap = tableObj.getProperties();
- StringBuilder propertiesString = new StringBuilder();
- if (propertiesMap != null) {
- counter = 0;
- for (Map.Entry<String, Object> entry : propertiesMap.entrySet()) {
- Object ot = entry.getValue();
- String value = ot + "";
- if (ot instanceof String) {
- value = "'" + value + "'";
- } else if (ot instanceof Map) {
- @SuppressWarnings("unchecked")
- Map<String, Object> otMap = (Map<String, Object>) ot;
- value = "{" + MusicUtil.jsonMaptoSqlString(otMap, ",") + "}";
- }
-
- propertiesString.append(entry.getKey() + "=" + value + "");
- if (counter != propertiesMap.size() - 1)
- propertiesString.append(" AND ");
-
- counter = counter + 1;
- }
- }
-
- queryObject.appendQueryString(
- "CREATE TABLE " + keyspace + "." + tablename + " " + fieldsString);
-
- if (propertiesMap != null)
- queryObject.appendQueryString(" WITH " + propertiesString);
-
- queryObject.appendQueryString(";");
- ResultType result = ResultType.FAILURE;
-
+ @ApiResponses(value={
+ @ApiResponse(code=200, message = "Success",examples = @Example( value = {
+ @ExampleProperty(mediaType="application/json",value =
+ "{\"message\" : \"Tablename <tablename> Created under keyspace <keyspace>\","
+ + "\"status\" : \"SUCCESS\"}")
+ })),
+ @ApiResponse(code=400, message = "Failure",examples = @Example( value = {
+ @ExampleProperty(mediaType="application/json",value =
+ "{\"error\" : \"<errorMessage>\","
+ + "\"status\" : \"FAILURE\"}")
+ }))
+ })
+ public Response createTable(
+ @ApiParam(value = "Major Version",required = true) @PathParam("version") String version,
+ @ApiParam(value = "Minor Version",required = false) @HeaderParam(XMINORVERSION) String minorVersion,
+ @ApiParam(value = "Patch Version",required = false) @HeaderParam(XPATCHVERSION) String patchVersion,
+ @ApiParam(value = "AID", required = false, hidden = true) @HeaderParam("aid") String aid,
+ @ApiParam(value = "Application namespace",required = false, hidden = true) @HeaderParam(NS) String ns,
+ @ApiParam(value = "Authorization", required = true) @HeaderParam(MusicUtil.AUTHORIZATION) String authorization,
+ JsonTable tableObj,
+ @ApiParam(value = "Keyspace Name",required = true) @PathParam("keyspace") String keyspace,
+ @ApiParam(value = "Table Name",required = true) @PathParam("tablename") String tablename) throws Exception {