use of com.google.common.reflect.TypeToken in project zeppelin by apache.
the class NotebookRestApi method putNotePermissions.
/**
* set note authorization information
*/
@PUT
@Path("{noteId}/permissions")
@ZeppelinApi
public Response putNotePermissions(@PathParam("noteId") String noteId, String req) throws IOException {
String principal = SecurityUtils.getPrincipal();
HashSet<String> roles = SecurityUtils.getRoles();
HashSet<String> userAndRoles = new HashSet<>();
userAndRoles.add(principal);
userAndRoles.addAll(roles);
checkIfUserIsAnon(getBlockNotAuthenticatedUserErrorMsg());
checkIfUserIsOwner(noteId, ownerPermissionError(userAndRoles, notebookAuthorization.getOwners(noteId)));
HashMap<String, HashSet<String>> permMap = gson.fromJson(req, new TypeToken<HashMap<String, HashSet<String>>>() {
}.getType());
Note note = notebook.getNote(noteId);
LOG.info("Set permissions {} {} {} {} {}", noteId, principal, permMap.get("owners"), permMap.get("readers"), permMap.get("writers"));
HashSet<String> readers = permMap.get("readers");
HashSet<String> owners = permMap.get("owners");
HashSet<String> writers = permMap.get("writers");
// Set readers, if writers and owners is empty -> set to user requesting the change
if (readers != null && !readers.isEmpty()) {
if (writers.isEmpty()) {
writers = Sets.newHashSet(SecurityUtils.getPrincipal());
}
if (owners.isEmpty()) {
owners = Sets.newHashSet(SecurityUtils.getPrincipal());
}
}
// Set writers, if owners is empty -> set to user requesting the change
if (writers != null && !writers.isEmpty()) {
if (owners.isEmpty()) {
owners = Sets.newHashSet(SecurityUtils.getPrincipal());
}
}
notebookAuthorization.setReaders(noteId, readers);
notebookAuthorization.setWriters(noteId, writers);
notebookAuthorization.setOwners(noteId, owners);
LOG.debug("After set permissions {} {} {}", notebookAuthorization.getOwners(noteId), notebookAuthorization.getReaders(noteId), notebookAuthorization.getWriters(noteId));
AuthenticationInfo subject = new AuthenticationInfo(SecurityUtils.getPrincipal());
note.persist(subject);
notebookServer.broadcastNote(note);
notebookServer.broadcastNoteList(subject, userAndRoles);
return new JsonResponse<>(Status.OK).build();
}
use of com.google.common.reflect.TypeToken in project weave by continuuity.
the class ArgumentsCodec method deserialize.
@Override
public Arguments deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
JsonObject jsonObj = json.getAsJsonObject();
List<String> arguments = context.deserialize(jsonObj.get("arguments"), new TypeToken<List<String>>() {
}.getType());
Map<String, Collection<String>> args = context.deserialize(jsonObj.get("runnableArguments"), new TypeToken<Map<String, Collection<String>>>() {
}.getType());
ImmutableMultimap.Builder<String, String> builder = ImmutableMultimap.builder();
for (Map.Entry<String, Collection<String>> entry : args.entrySet()) {
builder.putAll(entry.getKey(), entry.getValue());
}
return new Arguments(arguments, builder.build());
}
use of com.google.common.reflect.TypeToken in project weave by continuuity.
the class WeaveSpecificationCodec method deserialize.
@Override
public WeaveSpecification deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
JsonObject jsonObj = json.getAsJsonObject();
String name = jsonObj.get("name").getAsString();
Map<String, RuntimeSpecification> runnables = context.deserialize(jsonObj.get("runnables"), new TypeToken<Map<String, RuntimeSpecification>>() {
}.getType());
List<WeaveSpecification.Order> orders = context.deserialize(jsonObj.get("orders"), new TypeToken<List<WeaveSpecification.Order>>() {
}.getType());
JsonElement handler = jsonObj.get("handler");
EventHandlerSpecification eventHandler = null;
if (handler != null && !handler.isJsonNull()) {
eventHandler = context.deserialize(handler, EventHandlerSpecification.class);
}
return new DefaultWeaveSpecification(name, runnables, orders, eventHandler);
}
use of com.google.common.reflect.TypeToken in project EventHub by Codecademy.
the class BatchTrackEvent method execute.
@Override
public synchronized void execute(final HttpServletRequest request, final HttpServletResponse response) throws IOException {
List<Map<String, String>> events = gson.fromJson(request.getParameter("events"), new TypeToken<List<Map<String, String>>>() {
}.getType());
List<Long> eventIds = Lists.newArrayList();
PrintWriter writer = response.getWriter();
for (Map<String, String> eventMap : events) {
String date = eventMap.get("date");
if (date == null) {
date = dateHelper.getDate();
}
Event event = new Event.Builder(eventMap.get("event_type"), eventMap.get("external_user_id"), date, eventMap).build();
eventIds.add(eventHub.addEvent(event));
}
writer.println(gson.toJson(eventIds));
}
use of com.google.common.reflect.TypeToken in project retrofit by square.
the class RxJava2CallAdapterFactoryTest method responseTypes.
@Test
public void responseTypes() {
Type oBodyClass = new TypeToken<Observable<String>>() {
}.getType();
assertThat(factory.get(oBodyClass, NO_ANNOTATIONS, retrofit).responseType()).isEqualTo(String.class);
Type sBodyClass = new TypeToken<Single<String>>() {
}.getType();
assertThat(factory.get(sBodyClass, NO_ANNOTATIONS, retrofit).responseType()).isEqualTo(String.class);
Type mBodyClass = new TypeToken<Maybe<String>>() {
}.getType();
assertThat(factory.get(sBodyClass, NO_ANNOTATIONS, retrofit).responseType()).isEqualTo(String.class);
Type fBodyClass = new TypeToken<Flowable<String>>() {
}.getType();
assertThat(factory.get(sBodyClass, NO_ANNOTATIONS, retrofit).responseType()).isEqualTo(String.class);
Type oBodyWildcard = new TypeToken<Observable<? extends String>>() {
}.getType();
assertThat(factory.get(oBodyWildcard, NO_ANNOTATIONS, retrofit).responseType()).isEqualTo(String.class);
Type sBodyWildcard = new TypeToken<Single<? extends String>>() {
}.getType();
assertThat(factory.get(sBodyWildcard, NO_ANNOTATIONS, retrofit).responseType()).isEqualTo(String.class);
Type mBodyWildcard = new TypeToken<Maybe<? extends String>>() {
}.getType();
assertThat(factory.get(sBodyWildcard, NO_ANNOTATIONS, retrofit).responseType()).isEqualTo(String.class);
Type fBodyWildcard = new TypeToken<Flowable<? extends String>>() {
}.getType();
assertThat(factory.get(sBodyWildcard, NO_ANNOTATIONS, retrofit).responseType()).isEqualTo(String.class);
Type oBodyGeneric = new TypeToken<Observable<List<String>>>() {
}.getType();
assertThat(factory.get(oBodyGeneric, NO_ANNOTATIONS, retrofit).responseType()).isEqualTo(new TypeToken<List<String>>() {
}.getType());
Type sBodyGeneric = new TypeToken<Single<List<String>>>() {
}.getType();
assertThat(factory.get(sBodyGeneric, NO_ANNOTATIONS, retrofit).responseType()).isEqualTo(new TypeToken<List<String>>() {
}.getType());
Type mBodyGeneric = new TypeToken<Maybe<List<String>>>() {
}.getType();
assertThat(factory.get(sBodyGeneric, NO_ANNOTATIONS, retrofit).responseType()).isEqualTo(new TypeToken<List<String>>() {
}.getType());
Type fBodyGeneric = new TypeToken<Flowable<List<String>>>() {
}.getType();
assertThat(factory.get(sBodyGeneric, NO_ANNOTATIONS, retrofit).responseType()).isEqualTo(new TypeToken<List<String>>() {
}.getType());
Type oResponseClass = new TypeToken<Observable<Response<String>>>() {
}.getType();
assertThat(factory.get(oResponseClass, NO_ANNOTATIONS, retrofit).responseType()).isEqualTo(String.class);
Type sResponseClass = new TypeToken<Single<Response<String>>>() {
}.getType();
assertThat(factory.get(sResponseClass, NO_ANNOTATIONS, retrofit).responseType()).isEqualTo(String.class);
Type mResponseClass = new TypeToken<Maybe<Response<String>>>() {
}.getType();
assertThat(factory.get(sResponseClass, NO_ANNOTATIONS, retrofit).responseType()).isEqualTo(String.class);
Type fResponseClass = new TypeToken<Flowable<Response<String>>>() {
}.getType();
assertThat(factory.get(sResponseClass, NO_ANNOTATIONS, retrofit).responseType()).isEqualTo(String.class);
Type oResponseWildcard = new TypeToken<Observable<Response<? extends String>>>() {
}.getType();
assertThat(factory.get(oResponseWildcard, NO_ANNOTATIONS, retrofit).responseType()).isEqualTo(String.class);
Type sResponseWildcard = new TypeToken<Single<Response<? extends String>>>() {
}.getType();
assertThat(factory.get(sResponseWildcard, NO_ANNOTATIONS, retrofit).responseType()).isEqualTo(String.class);
Type mResponseWildcard = new TypeToken<Maybe<Response<? extends String>>>() {
}.getType();
assertThat(factory.get(sResponseWildcard, NO_ANNOTATIONS, retrofit).responseType()).isEqualTo(String.class);
Type fResponseWildcard = new TypeToken<Flowable<Response<? extends String>>>() {
}.getType();
assertThat(factory.get(sResponseWildcard, NO_ANNOTATIONS, retrofit).responseType()).isEqualTo(String.class);
Type oResultClass = new TypeToken<Observable<Result<String>>>() {
}.getType();
assertThat(factory.get(oResultClass, NO_ANNOTATIONS, retrofit).responseType()).isEqualTo(String.class);
Type sResultClass = new TypeToken<Single<Result<String>>>() {
}.getType();
assertThat(factory.get(sResultClass, NO_ANNOTATIONS, retrofit).responseType()).isEqualTo(String.class);
Type mResultClass = new TypeToken<Maybe<Result<String>>>() {
}.getType();
assertThat(factory.get(sResultClass, NO_ANNOTATIONS, retrofit).responseType()).isEqualTo(String.class);
Type fResultClass = new TypeToken<Flowable<Result<String>>>() {
}.getType();
assertThat(factory.get(sResultClass, NO_ANNOTATIONS, retrofit).responseType()).isEqualTo(String.class);
Type oResultWildcard = new TypeToken<Observable<Result<? extends String>>>() {
}.getType();
assertThat(factory.get(oResultWildcard, NO_ANNOTATIONS, retrofit).responseType()).isEqualTo(String.class);
Type sResultWildcard = new TypeToken<Single<Result<? extends String>>>() {
}.getType();
assertThat(factory.get(sResultWildcard, NO_ANNOTATIONS, retrofit).responseType()).isEqualTo(String.class);
Type mResultWildcard = new TypeToken<Maybe<Result<? extends String>>>() {
}.getType();
assertThat(factory.get(sResultWildcard, NO_ANNOTATIONS, retrofit).responseType()).isEqualTo(String.class);
Type fResultWildcard = new TypeToken<Flowable<Result<? extends String>>>() {
}.getType();
assertThat(factory.get(sResultWildcard, NO_ANNOTATIONS, retrofit).responseType()).isEqualTo(String.class);
}
Aggregations