Sonar Fixes - MusicDataStoreHandle.java
[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             return response.entity(new JsonResponse(ResultType.FAILURE).setError(e.getMessage()).toMap()).build();
116         }
117         if (appName == null || userId == null || isAAF == null || password == null) {
118             logger.error(EELFLoggerDelegate.errorLogger, "Unauthorized: Please check the request parameters. Some of the required values appName(ns), userId, password, isAAF are missing.", AppMessages.MISSINGINFO,
119                             ErrorSeverity.CRITICAL, ErrorTypes.AUTHENTICATIONERROR);
120             resultMap.put("Exception",
121                             "Unauthorized: Please check the request parameters. Some of the required values appName(ns), userId, password, isAAF are missing.");
122             return response.status(Status.UNAUTHORIZED).entity(resultMap).build();
123         }
124
125         PreparedQueryObject pQuery = new PreparedQueryObject();
126         /*
127          * pQuery.appendQueryString(
128          * "select uuid from admin.keyspace_master where application_name = ? allow filtering"
129          * ); pQuery.addValue(MusicUtil.convertToActualDataType(DataType.text(),
130          * appName)); ResultSet rs = MusicCore.get(pQuery); if (!rs.all().isEmpty()) {
131          * logger.error(EELFLoggerDelegate.errorLogger,"", AppMessages.INCORRECTDATA
132          * ,ErrorSeverity.CRITICAL, ErrorTypes.GENERALSERVICEERROR);
133          * response.status(Status.BAD_REQUEST); return response.entity(new
134          * JsonResponse(ResultType.FAILURE).setError("Application " + appName +
135          * " has already been onboarded. Please contact admin.").toMap()).build(); }
136          */
137         //pQuery = new PreparedQueryObject();
138         String uuid = CachingUtil.generateUUID();
139         pQuery.appendQueryString(
140                         "INSERT INTO admin.keyspace_master (uuid, keyspace_name, application_name, is_api, "
141                                         + "password, username, is_aaf) VALUES (?,?,?,?,?,?,?)");
142         pQuery.addValue(MusicUtil.convertToActualDataType(DataType.uuid(), uuid));
143         pQuery.addValue(MusicUtil.convertToActualDataType(DataType.text(),keyspace_name));
144         pQuery.addValue(MusicUtil.convertToActualDataType(DataType.text(), appName));
145         pQuery.addValue(MusicUtil.convertToActualDataType(DataType.cboolean(), "True"));
146         pQuery.addValue(MusicUtil.convertToActualDataType(DataType.text(), BCrypt.hashpw(password, BCrypt.gensalt())));
147         pQuery.addValue(MusicUtil.convertToActualDataType(DataType.text(), userId));
148         pQuery.addValue(MusicUtil.convertToActualDataType(DataType.cboolean(), isAAF));
149
150         String returnStr = MusicCore.eventualPut(pQuery).toString();
151         if (returnStr.contains("Failure")) {
152             logger.error(EELFLoggerDelegate.errorLogger,"", AppMessages.INCORRECTDATA  ,ErrorSeverity.CRITICAL, ErrorTypes.GENERALSERVICEERROR);
153             response.status(Status.BAD_REQUEST);
154             return response.entity(new JsonResponse(ResultType.FAILURE).setError("Oops. Something wrong with onboarding process. "
155                     + "Please retry later or contact admin.").toMap()).build();
156         }
157         CachingUtil.updateisAAFCache(appName, isAAF);
158         resultMap.put("Success", "Your application " + appName + " has been onboarded with MUSIC.");
159         resultMap.put("Generated AID", uuid);
160         return response.status(Status.OK).entity(resultMap).build();
161     }
162
163
164     @POST
165     @Path("/search")
166     @ApiOperation(value = "Search Onboard application", response = String.class)
167     @Consumes(MediaType.APPLICATION_JSON)
168     @Produces(MediaType.APPLICATION_JSON)
169     public Response getOnboardedInfoSearch(JsonOnboard jsonObj,
170             @ApiParam(value = "Authorization", required = true) @HeaderParam(MusicUtil.AUTHORIZATION) String authorization) throws Exception {
171         ResponseBuilder response = Response.noContent().header("X-latestVersion", MusicUtil.getVersion());
172         Map<String, Object> resultMap = new HashMap<>();
173         String appName = jsonObj.getAppname();
174         String uuid = jsonObj.getAid();
175         String isAAF = jsonObj.getIsAAF();
176
177         try {
178             if (!MusicAuthentication.authenticateAdmin(authorization)) {
179                 logger.error(EELFLoggerDelegate.errorLogger, "", AppMessages.MISSINGDATA, ErrorSeverity.CRITICAL,
180                         ErrorTypes.AUTHENTICATIONERROR);
181                 response.status(Status.UNAUTHORIZED);
182                 return response
183                         .entity(new JsonResponse(ResultType.FAILURE)
184                                 .setError("Unauthorized: Please check admin username,password and try again").toMap())
185                         .build();
186             }
187         } catch (Exception e) {
188             return response.entity(new JsonResponse(ResultType.FAILURE).setError(e.getMessage()).toMap()).build();
189         }
190         if (appName == null && uuid == null && isAAF == null) {
191             logger.error(EELFLoggerDelegate.errorLogger, "Unauthorized: Please check the request parameters. Enter atleast one of the following parameters: appName(ns), aid, isAAF.", AppMessages.MISSINGINFO,
192                             ErrorSeverity.CRITICAL, ErrorTypes.AUTHENTICATIONERROR);
193             resultMap.put("Exception",
194                             "Unauthorized: Please check the request parameters. Enter atleast one of the following parameters: appName(ns), aid, isAAF.");
195             return response.status(Status.BAD_REQUEST).entity(resultMap).build();
196         }
197
198         PreparedQueryObject pQuery = new PreparedQueryObject();
199         String cql = "select uuid, keyspace_name from admin.keyspace_master where ";
200         if (appName != null)
201             cql = cql + "application_name = ? AND ";
202         if (uuid != null)
203             cql = cql + "uuid = ? AND ";
204         if (isAAF != null)
205             cql = cql + "is_aaf = ?";
206
207         if (cql.endsWith("AND "))
208             cql = cql.trim().substring(0, cql.length() - 4);
209         logger.info("Query in callback is: " + cql);
210         cql = cql + " allow filtering";
211         pQuery.appendQueryString(cql);
212         if (appName != null)
213             pQuery.addValue(MusicUtil.convertToActualDataType(DataType.text(), appName));
214         if (uuid != null)
215             pQuery.addValue(MusicUtil.convertToActualDataType(DataType.uuid(), uuid));
216         if (isAAF != null)
217             pQuery.addValue(MusicUtil.convertToActualDataType(DataType.cboolean(),
218                             Boolean.parseBoolean(isAAF)));
219         ResultSet rs = MusicCore.get(pQuery);
220         Iterator<Row> it = rs.iterator();
221         while (it.hasNext()) {
222             Row row = it.next();
223             resultMap.put(row.getUUID("uuid").toString(), row.getString("keyspace_name"));
224         }
225         if (resultMap.isEmpty()) {
226             if (uuid != null) {
227                 logger.error(EELFLoggerDelegate.errorLogger,"", AppMessages.INCORRECTDATA  ,ErrorSeverity.CRITICAL, ErrorTypes.GENERALSERVICEERROR);
228                 response.status(Status.BAD_REQUEST);
229                 return response.entity(new JsonResponse(ResultType.FAILURE).setError("Please make sure Aid is correct and application is onboarded.").toMap()).build();
230
231             } else {
232                 logger.error(EELFLoggerDelegate.errorLogger,"", AppMessages.INCORRECTDATA  ,ErrorSeverity.CRITICAL, ErrorTypes.GENERALSERVICEERROR);
233                 response.status(Status.BAD_REQUEST);
234                 return response.entity(new JsonResponse(ResultType.FAILURE).setError("Application is not onboarded. Please make sure all the information is correct.").toMap()).build();
235             }
236         }
237         return response.status(Status.OK).entity(resultMap).build();
238     }
239
240
241     @DELETE
242     @Path("/onboardAppWithMusic")
243     @ApiOperation(value = "Delete Onboard application", response = String.class)
244     @Consumes(MediaType.APPLICATION_JSON)
245     @Produces(MediaType.APPLICATION_JSON)
246     public Response deleteOnboardApp(JsonOnboard jsonObj,
247             @ApiParam(value = "Authorization", required = true) @HeaderParam(MusicUtil.AUTHORIZATION) String authorization) throws Exception {
248         ResponseBuilder response = Response.noContent().header("X-latestVersion", MusicUtil.getVersion());
249         Map<String, Object> resultMap = new HashMap<>();
250         String appName = jsonObj.getAppname();
251         String aid = jsonObj.getAid();
252         PreparedQueryObject pQuery = new PreparedQueryObject();
253         String consistency = MusicUtil.EVENTUAL;;
254         try {
255             if (!MusicAuthentication.authenticateAdmin(authorization)) {
256                 logger.error(EELFLoggerDelegate.errorLogger, "", AppMessages.MISSINGDATA, ErrorSeverity.CRITICAL,
257                         ErrorTypes.AUTHENTICATIONERROR);
258                 response.status(Status.UNAUTHORIZED);
259                 return response
260                         .entity(new JsonResponse(ResultType.FAILURE)
261                                 .setError("Unauthorized: Please check admin username,password and try again").toMap())
262                         .build();
263             }
264         } catch (Exception e) {
265             return response.entity(new JsonResponse(ResultType.FAILURE).setError(e.getMessage()).toMap()).build();
266         }
267         if (appName == null && aid == null) {
268             logger.error(EELFLoggerDelegate.errorLogger, "Please make sure either appName(ns) or Aid is present", AppMessages.MISSINGINFO,
269                             ErrorSeverity.CRITICAL, ErrorTypes.DATAERROR);
270             resultMap.put("Exception", "Please make sure either appName(ns) or Aid is present");
271             return response.status(Status.BAD_REQUEST).entity(resultMap).build();
272         }
273         if (aid != null) {
274             if ( KEYSPACE_ACTIVE ) {
275               pQuery.appendQueryString(
276                               "SELECT keyspace_name FROM admin.keyspace_master WHERE uuid = ?");
277               pQuery.addValue(MusicUtil.convertToActualDataType(DataType.uuid(),
278                               UUID.fromString(aid)));
279               Row row = MusicCore.get(pQuery).one();
280               if (row != null) {
281                   String ks = row.getString("keyspace_name");
282                   if (!ks.equals(MusicUtil.DEFAULTKEYSPACENAME)) {
283                       PreparedQueryObject queryObject = new PreparedQueryObject();
284                       queryObject.appendQueryString("DROP KEYSPACE IF EXISTS " + ks + ";");
285                       MusicCore.nonKeyRelatedPut(queryObject, consistency);
286                   }
287               }
288             }
289             pQuery = new PreparedQueryObject();
290             pQuery.appendQueryString("delete from admin.keyspace_master where uuid = ? IF EXISTS");
291             pQuery.addValue(MusicUtil.convertToActualDataType(DataType.uuid(),
292                             UUID.fromString(aid)));
293             ResultType result = MusicCore.nonKeyRelatedPut(pQuery, consistency);
294             if (result == ResultType.SUCCESS) {
295                 resultMap.put("Success", "Your application has been deleted successfully");
296             } else {
297                 resultMap.put("Exception",
298                                 "Oops. Something went wrong. Please make sure Aid is correct or Application is onboarded");
299                 logger.error(EELFLoggerDelegate.errorLogger, "Oops. Something went wrong. Please make sure Aid is correct or Application is onboarded", AppMessages.INCORRECTDATA,
300                                 ErrorSeverity.CRITICAL, ErrorTypes.DATAERROR);
301                 return response.status(Status.BAD_REQUEST).entity(resultMap).build();
302
303             }
304             return response.status(Status.OK).entity(resultMap).build();
305         }
306
307         pQuery.appendQueryString(
308                         "select uuid from admin.keyspace_master where application_name = ? allow filtering");
309         pQuery.addValue(MusicUtil.convertToActualDataType(DataType.text(), appName));
310         ResultSet rs = MusicCore.get(pQuery);
311         List<Row> rows = rs.all();
312         String uuid = null;
313         if (rows.isEmpty()) {
314             resultMap.put("Exception",
315                             "Application not found. Please make sure Application exists.");
316             logger.error(EELFLoggerDelegate.errorLogger, "Application not found. Please make sure Application exists.", AppMessages.INCORRECTDATA,
317                             ErrorSeverity.CRITICAL, ErrorTypes.DATAERROR);
318             return response.status(Status.BAD_REQUEST).entity(resultMap).build();
319         } else if (rows.size() == 1) {
320             uuid = rows.get(0).getUUID("uuid").toString();
321             pQuery = new PreparedQueryObject();
322             pQuery.appendQueryString(
323                             "SELECT keyspace_name FROM admin.keyspace_master WHERE uuid = ?");
324             pQuery.addValue(MusicUtil.convertToActualDataType(DataType.uuid(),
325                             UUID.fromString(uuid)));
326             Row row = MusicCore.get(pQuery).one();
327             String ks = row.getString("keyspace_name");
328             if (!ks.equals(MusicUtil.DEFAULTKEYSPACENAME)) {
329                 PreparedQueryObject queryObject = new PreparedQueryObject();
330                 queryObject.appendQueryString("DROP KEYSPACE " + ks + ";");
331                 MusicCore.nonKeyRelatedPut(queryObject, consistency);
332             }
333
334             pQuery = new PreparedQueryObject();
335             pQuery.appendQueryString("delete from admin.keyspace_master where uuid = ?");
336             pQuery.addValue(MusicUtil.convertToActualDataType(DataType.uuid(),
337                             UUID.fromString(uuid)));
338             MusicCore.eventualPut(pQuery);
339             resultMap.put("Success", "Your application " + appName + " has been deleted.");
340             return response.status(Status.OK).entity(resultMap).build();
341         } else {
342             resultMap.put("Failure",
343                             "More than one Aid exists for this application, so please provide Aid.");
344             logger.error(EELFLoggerDelegate.errorLogger, "More than one Aid exists for this application, so please provide Aid.", AppMessages.MULTIPLERECORDS,
345                             ErrorSeverity.CRITICAL, ErrorTypes.DATAERROR);
346             return response.status(Status.BAD_REQUEST).entity(resultMap).build();
347         }
348     }
349
350
351     @PUT
352     @Path("/onboardAppWithMusic")
353     @ApiOperation(value = "Update Onboard application", response = String.class)
354     @Consumes(MediaType.APPLICATION_JSON)
355     @Produces(MediaType.APPLICATION_JSON)
356     public Response updateOnboardApp(JsonOnboard jsonObj,
357             @ApiParam(value = "Authorization", required = true) @HeaderParam(MusicUtil.AUTHORIZATION) String authorization) throws Exception {
358         ResponseBuilder response = Response.noContent().header("X-latestVersion", MusicUtil.getVersion());
359         Map<String, Object> resultMap = new HashMap<>();
360         String aid = jsonObj.getAid();
361         String appName = jsonObj.getAppname();
362         String userId = jsonObj.getUserId();
363         String isAAF = jsonObj.getIsAAF();
364         String password = jsonObj.getPassword();
365         String consistency = "eventual";
366         PreparedQueryObject pQuery;
367         try {
368             if (!MusicAuthentication.authenticateAdmin(authorization)) {
369                 logger.error(EELFLoggerDelegate.errorLogger, "", AppMessages.MISSINGDATA, ErrorSeverity.CRITICAL,
370                         ErrorTypes.AUTHENTICATIONERROR);
371                 response.status(Status.UNAUTHORIZED);
372                 return response
373                         .entity(new JsonResponse(ResultType.FAILURE)
374                                 .setError("Unauthorized: Please check admin username,password and try again").toMap())
375                         .build();
376             }
377         } catch (Exception e) {
378             return response.entity(new JsonResponse(ResultType.FAILURE).setError(e.getMessage()).toMap()).build();
379         }
380         if (aid == null) {
381             resultMap.put("Exception", "Please make sure Aid is present");
382             logger.error(EELFLoggerDelegate.errorLogger, "Please make sure Aid is present", AppMessages.MISSINGDATA,
383                             ErrorSeverity.CRITICAL, ErrorTypes.DATAERROR);
384             return response.status(Status.BAD_REQUEST).entity(resultMap).build();
385         }
386
387         if (appName == null && userId == null && password == null && isAAF == null) {
388             resultMap.put("Exception",
389                             "No parameters found to update. Please update atleast one parameter.");
390             logger.error(EELFLoggerDelegate.errorLogger, "No parameters found to update. Please update atleast one parameter.", AppMessages.MISSINGDATA,
391                             ErrorSeverity.CRITICAL, ErrorTypes.DATAERROR);
392             return response.status(Status.BAD_REQUEST).entity(resultMap).build();
393         }
394
395         if (appName != null) {
396             pQuery = new PreparedQueryObject();
397             pQuery.appendQueryString(
398                             "select uuid from admin.keyspace_master where application_name = ? allow filtering");
399             pQuery.addValue(MusicUtil.convertToActualDataType(DataType.text(), appName));
400             ResultSet rs = MusicCore.get(pQuery);
401             if (!rs.all().isEmpty()) {
402                 resultMap.put("Exception", "Application " + appName
403                                 + " has already been onboarded. Please contact admin.");
404                 logger.error(EELFLoggerDelegate.errorLogger, "Application " + appName+"has already been onboarded. Please contact admin.", AppMessages.ALREADYEXIST,
405                                 ErrorSeverity.CRITICAL, ErrorTypes.DATAERROR);
406                 return response.status(Status.BAD_REQUEST).entity(resultMap).build();
407             }
408         }
409
410         pQuery = new PreparedQueryObject();
411         StringBuilder preCql = new StringBuilder("UPDATE admin.keyspace_master SET ");
412         if (appName != null)
413             preCql.append(" application_name = ?,");
414         if (userId != null)
415             preCql.append(" username = ?,");
416         if (password != null)
417             preCql.append(" password = ?,");
418         if (isAAF != null)
419             preCql.append(" is_aaf = ?,");
420         preCql.deleteCharAt(preCql.length() - 1);
421         preCql.append(" WHERE uuid = ? IF EXISTS");
422         pQuery.appendQueryString(preCql.toString());
423         if (appName != null)
424             pQuery.addValue(MusicUtil.convertToActualDataType(DataType.text(), appName));
425         if (userId != null)
426             pQuery.addValue(MusicUtil.convertToActualDataType(DataType.text(), userId));
427         if (password != null)
428             pQuery.addValue(MusicUtil.convertToActualDataType(DataType.text(), BCrypt.hashpw(password, BCrypt.gensalt())));
429         if (isAAF != null)
430             pQuery.addValue(MusicUtil.convertToActualDataType(DataType.cboolean(), isAAF));
431
432         pQuery.addValue(MusicUtil.convertToActualDataType(DataType.uuid(), UUID.fromString(aid)));
433         ResultType result = MusicCore.nonKeyRelatedPut(pQuery, consistency);
434
435         if (result == ResultType.SUCCESS) {
436             resultMap.put("Success", "Your application has been updated successfully");
437         } else {
438             resultMap.put("Exception",
439                             "Oops. Something went wrong. Please make sure Aid is correct and application is onboarded");
440             logger.error(EELFLoggerDelegate.errorLogger, "Oops. Something went wrong. Please make sure Aid is correct and application is onboarded", AppMessages.INCORRECTDATA,
441                             ErrorSeverity.CRITICAL, ErrorTypes.DATAERROR);
442             return response.status(Status.BAD_REQUEST).entity(resultMap).build();
443         }
444
445         return response.status(Status.OK).entity(resultMap).build();
446     }
447
448     
449     
450   //Dashboard related calls
451     @GET
452     @Path("/getall")
453     @Produces(MediaType.APPLICATION_JSON)
454     @Consumes(MediaType.APPLICATION_JSON)
455     public List<Application> getall(@ApiParam(value = "Authorization", required = true) @HeaderParam(MusicUtil.AUTHORIZATION) String authorization) throws MusicServiceException{
456         List<Application> appList = new ArrayList<>();
457         ResponseBuilder response =
458                 Response.noContent().header("X-latestVersion", MusicUtil.getVersion());
459         PreparedQueryObject queryObject = new PreparedQueryObject();
460         queryObject.appendQueryString("SELECT *  FROM " + "admin" + "." + "keyspace_master" + ";");
461         ResultSet results = MusicCore.get(queryObject);
462         for(Row row : results) {
463             Application app = new Application();
464             app.setApplication_name(row.getString("application_name"));
465             app.setIs_aaf(row.getBool("is_aaf"));
466             app.setIs_api(row.getBool("is_api"));
467             app.setUsername(row.getString("username"));
468             app.setKeyspace_name(row.getString("keyspace_name"));
469             app.setUuid(row.getUUID("uuid").toString());
470             appList.add(app);
471         }
472         return appList;
473         
474         //return app;
475         
476     }
477     @DELETE
478     @Path("/delete")
479     @Produces(MediaType.APPLICATION_JSON)
480     @Consumes(MediaType.APPLICATION_JSON)
481     public boolean delete(@ApiParam(value = "Authorization", required = true) @HeaderParam(MusicUtil.AUTHORIZATION) String authorization,
482             @ApiParam(value = "uuid", required = true) @HeaderParam("uuid") String uuid) throws Exception {
483         ResponseBuilder response =
484                 Response.noContent().header("X-latestVersion", MusicUtil.getVersion());
485         PreparedQueryObject queryObject = new PreparedQueryObject();
486         queryObject.appendQueryString("delete from admin.keyspace_master where uuid=?");
487         queryObject.addValue(MusicUtil.convertToActualDataType(DataType.uuid(),uuid));
488         ResultType result;
489         try {
490          result = MusicCore.nonKeyRelatedPut(queryObject, "eventual");
491         }catch(Exception ex) {
492             return false;
493         }
494         return true;
495     }
496     
497     
498     @GET
499     @Path("/login")
500     @Produces(MediaType.APPLICATION_JSON)
501     @Consumes(MediaType.APPLICATION_JSON)
502     public boolean login(@ApiParam(value = "Authorization", required = true) @HeaderParam(MusicUtil.AUTHORIZATION) String authorization) throws Exception {
503        
504         boolean result =  MusicAuthentication.authenticateAdmin(authorization);
505         return result;
506     }
507 }