List of usage examples for com.google.common.collect ImmutableMultimap of
public static <K, V> ImmutableMultimap<K, V> of(K k1, V v1)
From source file:co.cask.cdap.gateway.handlers.AppFabricHttpHandler.java
private void dataList(HttpRequest request, HttpResponder responder, Data type, String name, String appId) { try {// ww w .j av a 2s. co m if ((name != null && name.isEmpty()) || (appId != null && appId.isEmpty())) { responder.sendString(HttpResponseStatus.BAD_REQUEST, "Empty name provided"); return; } String accountId = getAuthenticatedAccountId(request); Id.Program program = Id.Program.from(accountId, appId == null ? "" : appId, ""); String json = name != null ? getDataEntity(program, type, name) : appId != null ? listDataEntitiesByApp(program, type) : listDataEntities(program, type); if (json.isEmpty()) { responder.sendStatus(HttpResponseStatus.NOT_FOUND); } else { responder.sendByteArray(HttpResponseStatus.OK, json.getBytes(Charsets.UTF_8), ImmutableMultimap.of(HttpHeaders.Names.CONTENT_TYPE, "application/json")); } } catch (SecurityException e) { responder.sendStatus(HttpResponseStatus.UNAUTHORIZED); } catch (Throwable e) { LOG.error("Got exception : ", e); responder.sendStatus(HttpResponseStatus.INTERNAL_SERVER_ERROR); } }
From source file:co.cask.cdap.gateway.handlers.AppFabricHttpHandler.java
private void programListByDataAccess(HttpRequest request, HttpResponder responder, ProgramType type, Data data, String name) {/*from www . j av a 2 s. c o m*/ try { if (name.isEmpty()) { responder.sendString(HttpResponseStatus.BAD_REQUEST, data.prettyName().toLowerCase() + " name is empty"); return; } String accountId = getAuthenticatedAccountId(request); Id.Program programId = Id.Program.from(accountId, "", ""); String list = listProgramsByDataAccess(programId, type, data, name); if (list.isEmpty()) { responder.sendStatus(HttpResponseStatus.NOT_FOUND); } else { responder.sendByteArray(HttpResponseStatus.OK, list.getBytes(Charsets.UTF_8), ImmutableMultimap.of(HttpHeaders.Names.CONTENT_TYPE, "application/json")); } } catch (SecurityException e) { responder.sendStatus(HttpResponseStatus.UNAUTHORIZED); } catch (Throwable e) { LOG.error("Got exception:", e); responder.sendStatus(HttpResponseStatus.INTERNAL_SERVER_ERROR); } }