Update MUSIC test cases.
[music.git] / src / main / java / org / onap / music / rest / RestMusicAdminAPI.java
1 /*
2  * ============LICENSE_START==========================================
3  * org.onap.music
4  * ===================================================================
5  *  Copyright (c) 2017 AT&T Intellectual Property
6  * ===================================================================
7  * Modifications Copyright (C) 2018 IBM.
8  * ================================================================================
9  *  Licensed under the Apache License, Version 2.0 (the "License");
10  *  you may not use this file except in compliance with the License.
11  *  You may obtain a copy of the License at
12  *
13  *     http://www.apache.org/licenses/LICENSE-2.0
14  *
15  *  Unless required by applicable law or agreed to in writing, software
16  *  distributed under the License is distributed on an "AS IS" BASIS,
17  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18  *  See the License for the specific language governing permissions and
19  *  limitations under the License.
20  *
21  * ============LICENSE_END=============================================
22  * ====================================================================
23  */
24
25 package org.onap.music.rest;
26
27
28 import java.util.ArrayList;
29 import java.util.HashMap;
30 import java.util.Iterator;
31 import java.util.List;
32 import java.util.Map;
33 import java.util.UUID;
34
35 import javax.ws.rs.Consumes;
36 import javax.ws.rs.DELETE;
37 import javax.ws.rs.GET;
38 import javax.ws.rs.HeaderParam;
39 import javax.ws.rs.POST;
40 import javax.ws.rs.PUT;
41 import javax.ws.rs.Path;
42 import javax.ws.rs.Produces;
43 import javax.ws.rs.core.MediaType;
44 import javax.ws.rs.core.Response;
45 import javax.ws.rs.core.Response.ResponseBuilder;
46 import javax.ws.rs.core.Response.Status;
47
48 import org.mindrot.jbcrypt.BCrypt;
49 import org.onap.music.authentication.MusicAuthentication;
50 import org.onap.music.datastore.PreparedQueryObject;
51 import org.onap.music.datastore.jsonobjects.JsonOnboard;
52 import org.onap.music.eelf.logging.EELFLoggerDelegate;
53 import org.onap.music.eelf.logging.format.AppMessages;
54 import org.onap.music.eelf.logging.format.ErrorSeverity;
55 import org.onap.music.eelf.logging.format.ErrorTypes;
56 import org.onap.music.exceptions.MusicServiceException;
57 //import org.onap.music.main.CacheAccess;
58 import org.onap.music.main.CachingUtil;
59 import org.onap.music.main.MusicCore;
60 import org.onap.music.main.MusicUtil;
61 import org.onap.music.main.ResultType;
62 import org.onap.music.response.jsonobjects.JsonResponse;
63
64 import com.datastax.driver.core.DataType;
65 import com.datastax.driver.core.ResultSet;
66 import com.datastax.driver.core.Row;
67
68 import io.swagger.annotations.Api;
69 import io.swagger.annotations.ApiOperation;
70 import io.swagger.annotations.ApiParam;
71 //import java.util.Base64.Encoder;
72 //import java.util.Base64.Decoder;
73
74 @Path("/v2/admin")
75 // @Path("/v{version: [0-9]+}/admin")
76 // @Path("/admin")
77 @Api(value = "Admin Api", hidden = true)
78 public class RestMusicAdminAPI {
79     private static EELFLoggerDelegate logger =
80                     EELFLoggerDelegate.getLogger(RestMusicAdminAPI.class);
81     // Set to true in env like ONAP. Where access to creating and dropping keyspaces exist.    
82     private static final boolean KEYSPACE_ACTIVE = false;
83
84     /*
85      * API to onboard an application with MUSIC. This is the mandatory first step.
86      *
87      */
88     @POST
89     @Path("/onboardAppWithMusic")
90     @ApiOperation(value = "Onboard application", response = String.class)
91     @Consumes(MediaType.APPLICATION_JSON)
92     @Produces(MediaType.APPLICATION_JSON)
93     public Response onboardAppWithMusic(JsonOnboard jsonObj,
94             @ApiParam(value = "Authorization", required = true) @HeaderParam(MusicUtil.AUTHORIZATION) String authorization) throws Exception {
95         logger.info(EELFLoggerDelegate.errorLogger, "oboarding app");
96         ResponseBuilder response =
97                         Response.noContent().header("X-latestVersion", MusicUtil.getVersion());
98         Map<String, Object> resultMap = new HashMap<>();
99         String appName = jsonObj.getAppname();
100         String userId = jsonObj.getUserId();
101         String isAAF = jsonObj.getIsAAF();
102         String password = jsonObj.getPassword();
103         String keyspace_name = jsonObj.getKeyspace();
104         try {
105             if (!MusicAuthentication.authenticateAdmin(authorization)) {
106                 logger.error(EELFLoggerDelegate.errorLogger, "Unauthorized: Please check admin username,password and try again", AppMessages.MISSINGDATA, ErrorSeverity.CRITICAL,
107                         ErrorTypes.AUTHENTICATIONERROR);
108                 response.status(Status.UNAUTHORIZED);
109                 return response
110                         .entity(new JsonResponse(ResultType.FAILURE)
111                                 .setError("Unauthorized: Please check admin username,password and try again").toMap())
112                         .build();
113             }
114         } catch (Exception e) {
115                 logger.error(EELFLoggerDelegate.errorLogger, "Unable to authenticate", e);
116                 response.status(Status.UNAUTHORIZED);
117             return response.entity(new JsonResponse(ResultType.FAILURE).setError(e.getMessage()).toMap()).build();
118         }
119         if (appName == null || userId == null || isAAF == null || password == null) {
120             logger.error(EELFLoggerDelegate.errorLogger, "Unauthorized: Please check the request parameters. Some of the required values appName(ns), userId, password, isAAF are missing.", AppMessages.MISSINGINFO,
121                             ErrorSeverity.CRITICAL, ErrorTypes.AUTHENTICATIONERROR);
122             resultMap.put("Exception",
123                             "Unauthorized: Please check the request parameters. Some of the required values appName(ns), userId, password, isAAF are missing.");
124             return response.status(Status.UNAUTHORIZED).entity(resultMap).build();
125         }
126
127         PreparedQueryObject pQuery = new PreparedQueryObject();
128         /*
129          * pQuery.appendQueryString(
130          * "select uuid from admin.keyspace_master where application_name = ? allow filtering"
131          * ); pQuery.addValue(MusicUtil.convertToActualDataType(DataType.text(),
132          * appName)); ResultSet rs = MusicCore.get(pQuery); if (!rs.all().isEmpty()) {
133          * logger.error(EELFLoggerDelegate.errorLogger,"", AppMessages.INCORRECTDATA
134          * ,ErrorSeverity.CRITICAL, ErrorTypes.GENERALSERVICEERROR);
135          * response.status(Status.BAD_REQUEST); return response.entity(new
136          * JsonResponse(ResultType.FAILURE).setError("Application " + appName +
137          * " has already been onboarded. Please contact admin.").toMap()).build(); }
138          */
139         //pQuery = new PreparedQueryObject();
140         String uuid = CachingUtil.generateUUID();
141         pQuery.appendQueryString(
142                         "INSERT INTO admin.keyspace_master (uuid, keyspace_name, application_name, is_api, "
143                                         + "password, username, is_aaf) VALUES (?,?,?,?,?,?,?)");
144         pQuery.addValue(MusicUtil.convertToActualDataType(DataType.uuid(), uuid));
145         pQuery.addValue(MusicUtil.convertToActualDataType(DataType.text(),keyspace_name));
146         pQuery.addValue(MusicUtil.convertToActualDataType(DataType.text(), appName));
147         pQuery.addValue(MusicUtil.convertToActualDataType(DataType.cboolean(), "True"));
148         pQuery.addValue(MusicUtil.convertToActualDataType(DataType.text(), BCrypt.hashpw(password, BCrypt.gensalt())));
149         pQuery.addValue(MusicUtil.convertToActualDataType(DataType.text(), userId));
150         pQuery.addValue(MusicUtil.convertToActualDataType(DataType.cboolean(), isAAF));
151
152         String returnStr = MusicCore.eventualPut(pQuery).toString();
153         if (returnStr.contains("Failure")) {
154             logger.error(EELFLoggerDelegate.errorLogger,"", AppMessages.INCORRECTDATA  ,ErrorSeverity.CRITICAL, ErrorTypes.GENERALSERVICEERROR);
155             response.status(Status.BAD_REQUEST);
156             return response.entity(new JsonResponse(ResultType.FAILURE).setError("Oops. Something wrong with onboarding process. "
157                     + "Please retry later or contact admin.").toMap()).build();
158         }
159         CachingUtil.updateisAAFCache(appName, isAAF);
160         resultMap.put("Success", "Your application " + appName + " has been onboarded with MUSIC.");
161         resultMap.put("Generated AID", uuid);
162         return response.status(Status.OK).entity(resultMap).build();
163     }
164
165
166     @POST
167     @Path("/search")
168     @ApiOperation(value = "Search Onboard application", response = String.class)
169     @Consumes(MediaType.APPLICATION_JSON)
170     @Produces(MediaType.APPLICATION_JSON)
171     public Response getOnboardedInfoSearch(JsonOnboard jsonObj,
172             @ApiParam(value = "Authorization", required = true) @HeaderParam(MusicUtil.AUTHORIZATION) String authorization) throws Exception {
173         ResponseBuilder response = Response.noContent().header("X-latestVersion", MusicUtil.getVersion());
174         Map<String, Object> resultMap = new HashMap<>();
175         String appName = jsonObj.getAppname();
176         String uuid = jsonObj.getAid();
177         String isAAF = jsonObj.getIsAAF();
178
179         try {
180             if (!MusicAuthentication.authenticateAdmin(authorization)) {
181                 logger.error(EELFLoggerDelegate.errorLogger, "", AppMessages.MISSINGDATA, ErrorSeverity.CRITICAL,
182                         ErrorTypes.AUTHENTICATIONERROR);
183                 response.status(Status.UNAUTHORIZED);
184                 return response
185                         .entity(new JsonResponse(ResultType.FAILURE)
186                                 .setError("Unauthorized: Please check admin username,password and try again").toMap())
187                         .build();
188             }
189         } catch (Exception e) {
190             return response.entity(new JsonResponse(ResultType.FAILURE).setError(e.getMessage()).toMap()).build();
191         }
192         if (appName == null && uuid == null && isAAF == null) {
193             logger.error(EELFLoggerDelegate.errorLogger, "Unauthorized: Please check the request parameters. Enter atleast one of the following parameters: appName(ns), aid, isAAF.", AppMessages.MISSINGINFO,
194                             ErrorSeverity.CRITICAL, ErrorTypes.AUTHENTICATIONERROR);
195             resultMap.put("Exception",
196                             "Unauthorized: Please check the request parameters. Enter atleast one of the following parameters: appName(ns), aid, isAAF.");
197             return response.status(Status.BAD_REQUEST).entity(resultMap).build();
198         }
199
200         PreparedQueryObject pQuery = new PreparedQueryObject();
201         String cql = "select uuid, keyspace_name from admin.keyspace_master where ";
202         if (appName != null)
203             cql = cql + "application_name = ? AND ";
204         if (uuid != null)
205             cql = cql + "uuid = ? AND ";
206         if (isAAF != null)
207             cql = cql + "is_aaf = ?";
208
209         if (cql.endsWith("AND "))
210             cql = cql.trim().substring(0, cql.length() - 4);
211         logger.info("Query in callback is: " + cql);
212         cql = cql + " allow filtering";
213         pQuery.appendQueryString(cql);
214         if (appName != null)
215             pQuery.addValue(MusicUtil.convertToActualDataType(DataType.text(), appName));
216         if (uuid != null)
217             pQuery.addValue(MusicUtil.convertToActualDataType(DataType.uuid(), uuid));
218         if (isAAF != null)
219             pQuery.addValue(MusicUtil.convertToActualDataType(DataType.cboolean(),
220                             Boolean.parseBoolean(isAAF)));
221         ResultSet rs = MusicCore.get(pQuery);
222         Iterator<Row> it = rs.iterator();
223         while (it.hasNext()) {
224             Row row = it.next();
225             resultMap.put(row.getUUID("uuid").toString(), row.getString("keyspace_name"));
226         }
227         if (resultMap.isEmpty()) {
228             if (uuid != null) {
229                 logger.error(EELFLoggerDelegate.errorLogger,"", AppMessages.INCORRECTDATA  ,ErrorSeverity.CRITICAL, ErrorTypes.GENERALSERVICEERROR);
230                 response.status(Status.BAD_REQUEST);
231                 return response.entity(new JsonResponse(ResultType.FAILURE).setError("Please make sure Aid is correct and application is onboarded.").toMap()).build();
232
233             } else {
234                 logger.error(EELFLoggerDelegate.errorLogger,"", AppMessages.INCORRECTDATA  ,ErrorSeverity.CRITICAL, ErrorTypes.GENERALSERVICEERROR);
235                 response.status(Status.BAD_REQUEST);
236                 return response.entity(new JsonResponse(ResultType.FAILURE).setError("Application is not onboarded. Please make sure all the information is correct.").toMap()).build();
237             }
238         }
239         return response.status(Status.OK).entity(resultMap).build();
240     }
241
242
243     @DELETE
244     @Path("/onboardAppWithMusic")
245     @ApiOperation(value = "Delete Onboard application", response = String.class)
246     @Consumes(MediaType.APPLICATION_JSON)
247     @Produces(MediaType.APPLICATION_JSON)
248     public Response deleteOnboardApp(JsonOnboard jsonObj,
249             @ApiParam(value = "Authorization", required = true) @HeaderParam(MusicUtil.AUTHORIZATION) String authorization) throws Exception {
250         ResponseBuilder response = Response.noContent().header("X-latestVersion", MusicUtil.getVersion());
251         Map<String, Object> resultMap = new HashMap<>();
252         String appName = jsonObj.getAppname();
253         String aid = jsonObj.getAid();
254         PreparedQueryObject pQuery = new PreparedQueryObject();
255         String consistency = MusicUtil.EVENTUAL;;
256         try {
257             if (!MusicAuthentication.authenticateAdmin(authorization)) {
258                 logger.error(EELFLoggerDelegate.errorLogger, "", AppMessages.MISSINGDATA, ErrorSeverity.CRITICAL,
259                         ErrorTypes.AUTHENTICATIONERROR);
260                 response.status(Status.UNAUTHORIZED);
261                 return response
262                         .entity(new JsonResponse(ResultType.FAILURE)
263                                 .setError("Unauthorized: Please check admin username,password and try again").toMap())
264                         .build();
265             }
266         } catch (Exception e) {
267             return response.entity(new JsonResponse(ResultType.FAILURE).setError(e.getMessage()).toMap()).build();
268         }
269         if (appName == null && aid == null) {
270             logger.error(EELFLoggerDelegate.errorLogger, "Please make sure either appName(ns) or Aid is present", AppMessages.MISSINGINFO,
271                             ErrorSeverity.CRITICAL, ErrorTypes.DATAERROR);
272             resultMap.put("Exception", "Please make sure either appName(ns) or Aid is present");
273             return response.status(Status.BAD_REQUEST).entity(resultMap).build();
274         }
275         if (aid != null) {
276             if ( KEYSPACE_ACTIVE ) {
277               pQuery.appendQueryString(
278                               "SELECT keyspace_name FROM admin.keyspace_master WHERE uuid = ?");
279               pQuery.addValue(MusicUtil.convertToActualDataType(DataType.uuid(),
280                               UUID.fromString(aid)));
281               Row row = MusicCore.get(pQuery).one();
282               if (row != null) {
283                   String ks = row.getString("keyspace_name");
284                   if (!ks.equals(MusicUtil.DEFAULTKEYSPACENAME)) {
285                       PreparedQueryObject queryObject = new PreparedQueryObject();
286                       queryObject.appendQueryString("DROP KEYSPACE IF EXISTS " + ks + ";");
287                       MusicCore.nonKeyRelatedPut(queryObject, consistency);
288                   }
289               }
290             }
291             pQuery = new PreparedQueryObject();
292             pQuery.appendQueryString("delete from admin.keyspace_master where uuid = ? IF EXISTS");
293             pQuery.addValue(MusicUtil.convertToActualDataType(DataType.uuid(),
294                             UUID.fromString(aid)));
295             ResultType result = MusicCore.nonKeyRelatedPut(pQuery, consistency);
296             if (result == ResultType.SUCCESS) {
297                 resultMap.put("Success", "Your application has been deleted successfully");
298             } else {
299                 resultMap.put("Exception",
300                                 "Oops. Something went wrong. Please make sure Aid is correct or Application is onboarded");
301                 logger.error(EELFLoggerDelegate.errorLogger, "Oops. Something went wrong. Please make sure Aid is correct or Application is onboarded", AppMessages.INCORRECTDATA,
302                                 ErrorSeverity.CRITICAL, ErrorTypes.DATAERROR);
303                 return response.status(Status.BAD_REQUEST).entity(resultMap).build();
304
305             }
306             return response.status(Status.OK).entity(resultMap).build();
307         }
308
309         pQuery.appendQueryString(
310                         "select uuid from admin.keyspace_master where application_name = ? allow filtering");
311         pQuery.addValue(MusicUtil.convertToActualDataType(DataType.text(), appName));
312         ResultSet rs = MusicCore.get(pQuery);
313         List<Row> rows = rs.all();
314         String uuid = null;
315         if (rows.isEmpty()) {
316             resultMap.put("Exception",
317                             "Application not found. Please make sure Application exists.");
318             logger.error(EELFLoggerDelegate.errorLogger, "Application not found. Please make sure Application exists.", AppMessages.INCORRECTDATA,
319                             ErrorSeverity.CRITICAL, ErrorTypes.DATAERROR);
320             return response.status(Status.BAD_REQUEST).entity(resultMap).build();
321         } else if (rows.size() == 1) {
322             uuid = rows.get(0).getUUID("uuid").toString();
323             pQuery = new PreparedQueryObject();
324             pQuery.appendQueryString(
325                             "SELECT keyspace_name FROM admin.keyspace_master WHERE uuid = ?");
326             pQuery.addValue(MusicUtil.convertToActualDataType(DataType.uuid(),
327                             UUID.fromString(uuid)));
328             Row row = MusicCore.get(pQuery).one();
329             String ks = row.getString("keyspace_name");
330             if (!ks.equals(MusicUtil.DEFAULTKEYSPACENAME)) {
331                 PreparedQueryObject queryObject = new PreparedQueryObject();
332                 queryObject.appendQueryString("DROP KEYSPACE " + ks + ";");
333                 MusicCore.nonKeyRelatedPut(queryObject, consistency);
334             }
335
336             pQuery = new PreparedQueryObject();
337             pQuery.appendQueryString("delete from admin.keyspace_master where uuid = ?");
338             pQuery.addValue(MusicUtil.convertToActualDataType(DataType.uuid(),
339                             UUID.fromString(uuid)));
340             MusicCore.eventualPut(pQuery);
341             resultMap.put("Success", "Your application " + appName + " has been deleted.");
342             return response.status(Status.OK).entity(resultMap).build();
343         } else {
344             resultMap.put("Failure",
345                             "More than one Aid exists for this application, so please provide Aid.");
346             logger.error(EELFLoggerDelegate.errorLogger, "More than one Aid exists for this application, so please provide Aid.", AppMessages.MULTIPLERECORDS,
347                             ErrorSeverity.CRITICAL, ErrorTypes.DATAERROR);
348             return response.status(Status.BAD_REQUEST).entity(resultMap).build();
349         }
350     }
351
352
353     @PUT
354     @Path("/onboardAppWithMusic")
355     @ApiOperation(value = "Update Onboard application", response = String.class)
356     @Consumes(MediaType.APPLICATION_JSON)
357     @Produces(MediaType.APPLICATION_JSON)
358     public Response updateOnboardApp(JsonOnboard jsonObj,
359             @ApiParam(value = "Authorization", required = true) @HeaderParam(MusicUtil.AUTHORIZATION) String authorization) throws Exception {
360         ResponseBuilder response = Response.noContent().header("X-latestVersion", MusicUtil.getVersion());
361         Map<String, Object> resultMap = new HashMap<>();
362         String aid = jsonObj.getAid();
363         String appName = jsonObj.getAppname();
364         String userId = jsonObj.getUserId();
365         String isAAF = jsonObj.getIsAAF();
366         String password = jsonObj.getPassword();
367         String consistency = "eventual";
368         PreparedQueryObject pQuery;
369         try {
370             if (!MusicAuthentication.authenticateAdmin(authorization)) {
371                 logger.error(EELFLoggerDelegate.errorLogger, "", AppMessages.MISSINGDATA, ErrorSeverity.CRITICAL,
372                         ErrorTypes.AUTHENTICATIONERROR);
373                 response.status(Status.UNAUTHORIZED);
374                 return response
375                         .entity(new JsonResponse(ResultType.FAILURE)
376                                 .setError("Unauthorized: Please check admin username,password and try again").toMap())
377                         .build();
378             }
379         } catch (Exception e) {
380             return response.entity(new JsonResponse(ResultType.FAILURE).setError(e.getMessage()).toMap()).build();
381         }
382         if (aid == null) {
383             resultMap.put("Exception", "Please make sure Aid is present");
384             logger.error(EELFLoggerDelegate.errorLogger, "Please make sure Aid is present", AppMessages.MISSINGDATA,
385                             ErrorSeverity.CRITICAL, ErrorTypes.DATAERROR);
386             return response.status(Status.BAD_REQUEST).entity(resultMap).build();
387         }
388
389         if (appName == null && userId == null && password == null && isAAF == null) {
390             resultMap.put("Exception",
391                             "No parameters found to update. Please update atleast one parameter.");
392             logger.error(EELFLoggerDelegate.errorLogger, "No parameters found to update. Please update atleast one parameter.", AppMessages.MISSINGDATA,
393                             ErrorSeverity.CRITICAL, ErrorTypes.DATAERROR);
394             return response.status(Status.BAD_REQUEST).entity(resultMap).build();
395         }
396
397         if (appName != null) {
398             pQuery = new PreparedQueryObject();
399             pQuery.appendQueryString(
400                             "select uuid from admin.keyspace_master where application_name = ? allow filtering");
401             pQuery.addValue(MusicUtil.convertToActualDataType(DataType.text(), appName));
402             ResultSet rs = MusicCore.get(pQuery);
403             if (!rs.all().isEmpty()) {
404                 resultMap.put("Exception", "Application " + appName
405                                 + " has already been onboarded. Please contact admin.");
406                 logger.error(EELFLoggerDelegate.errorLogger, "Application " + appName+"has already been onboarded. Please contact admin.", AppMessages.ALREADYEXIST,
407                                 ErrorSeverity.CRITICAL, ErrorTypes.DATAERROR);
408                 return response.status(Status.BAD_REQUEST).entity(resultMap).build();
409             }
410         }
411
412         pQuery = new PreparedQueryObject();
413         StringBuilder preCql = new StringBuilder("UPDATE admin.keyspace_master SET ");
414         if (appName != null)
415             preCql.append(" application_name = ?,");
416         if (userId != null)
417             preCql.append(" username = ?,");
418         if (password != null)
419             preCql.append(" password = ?,");
420         if (isAAF != null)
421             preCql.append(" is_aaf = ?,");
422         preCql.deleteCharAt(preCql.length() - 1);
423         preCql.append(" WHERE uuid = ? IF EXISTS");
424         pQuery.appendQueryString(preCql.toString());
425         if (appName != null)
426             pQuery.addValue(MusicUtil.convertToActualDataType(DataType.text(), appName));
427         if (userId != null)
428             pQuery.addValue(MusicUtil.convertToActualDataType(DataType.text(), userId));
429         if (password != null)
430             pQuery.addValue(MusicUtil.convertToActualDataType(DataType.text(), BCrypt.hashpw(password, BCrypt.gensalt())));
431         if (isAAF != null)
432             pQuery.addValue(MusicUtil.convertToActualDataType(DataType.cboolean(), isAAF));
433
434         pQuery.addValue(MusicUtil.convertToActualDataType(DataType.uuid(), UUID.fromString(aid)));
435         ResultType result = MusicCore.nonKeyRelatedPut(pQuery, consistency);
436
437         if (result == ResultType.SUCCESS) {
438             resultMap.put("Success", "Your application has been updated successfully");
439         } else {
440             resultMap.put("Exception",
441                             "Oops. Something went wrong. Please make sure Aid is correct and application is onboarded");
442             logger.error(EELFLoggerDelegate.errorLogger, "Oops. Something went wrong. Please make sure Aid is correct and application is onboarded", AppMessages.INCORRECTDATA,
443                             ErrorSeverity.CRITICAL, ErrorTypes.DATAERROR);
444             return response.status(Status.BAD_REQUEST).entity(resultMap).build();
445         }
446
447         return response.status(Status.OK).entity(resultMap).build();
448     }
449
450     
451     
452   //Dashboard related calls
453     @GET
454     @Path("/getall")
455     @Produces(MediaType.APPLICATION_JSON)
456     @Consumes(MediaType.APPLICATION_JSON)
457     public List<Application> getall(@ApiParam(value = "Authorization", required = true) @HeaderParam(MusicUtil.AUTHORIZATION) String authorization) throws MusicServiceException{
458         List<Application> appList = new ArrayList<>();
459         ResponseBuilder response =
460                 Response.noContent().header("X-latestVersion", MusicUtil.getVersion());
461         PreparedQueryObject queryObject = new PreparedQueryObject();
462         queryObject.appendQueryString("SELECT *  FROM " + "admin" + "." + "keyspace_master" + ";");
463         ResultSet results = MusicCore.get(queryObject);
464         for(Row row : results) {
465             Application app = new Application();
466             app.setApplication_name(row.getString("application_name"));
467             app.setIs_aaf(row.getBool("is_aaf"));
468             app.setIs_api(row.getBool("is_api"));
469             app.setUsername(row.getString("username"));
470             app.setKeyspace_name(row.getString("keyspace_name"));
471             app.setUuid(row.getUUID("uuid").toString());
472             appList.add(app);
473         }
474         return appList;
475         
476         //return app;
477         
478     }
479     @DELETE
480     @Path("/delete")
481     @Produces(MediaType.APPLICATION_JSON)
482     @Consumes(MediaType.APPLICATION_JSON)
483     public boolean delete(@ApiParam(value = "Authorization", required = true) @HeaderParam(MusicUtil.AUTHORIZATION) String authorization,
484             @ApiParam(value = "uuid", required = true) @HeaderParam("uuid") String uuid) throws Exception {
485         ResponseBuilder response =
486                 Response.noContent().header("X-latestVersion", MusicUtil.getVersion());
487         PreparedQueryObject queryObject = new PreparedQueryObject();
488         queryObject.appendQueryString("delete from admin.keyspace_master where uuid=?");
489         queryObject.addValue(MusicUtil.convertToActualDataType(DataType.uuid(),uuid));
490         ResultType result;
491         try {
492          result = MusicCore.nonKeyRelatedPut(queryObject, "eventual");
493         }catch(Exception ex) {
494             return false;
495         }
496         return true;
497     }
498     
499     
500     @GET
501     @Path("/login")
502     @Produces(MediaType.APPLICATION_JSON)
503     @Consumes(MediaType.APPLICATION_JSON)
504     public boolean login(@ApiParam(value = "Authorization", required = true) @HeaderParam(MusicUtil.AUTHORIZATION) String authorization) throws Exception {
505        
506         boolean result =  MusicAuthentication.authenticateAdmin(authorization);
507         return result;
508     }
509 }