Search in sources :

Example 71 with TypeToken

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();
}
Also used : TypeToken(com.google.common.reflect.TypeToken) Note(org.apache.zeppelin.notebook.Note) AuthenticationInfo(org.apache.zeppelin.user.AuthenticationInfo) HashSet(java.util.HashSet) Path(javax.ws.rs.Path) ZeppelinApi(org.apache.zeppelin.annotation.ZeppelinApi) PUT(javax.ws.rs.PUT)

Example 72 with TypeToken

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());
}
Also used : TypeToken(com.google.common.reflect.TypeToken) Arguments(com.continuuity.weave.internal.Arguments) JsonObject(com.google.gson.JsonObject) Collection(java.util.Collection) ImmutableMultimap(com.google.common.collect.ImmutableMultimap) Map(java.util.Map)

Example 73 with TypeToken

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);
}
Also used : TypeToken(com.google.common.reflect.TypeToken) JsonElement(com.google.gson.JsonElement) JsonObject(com.google.gson.JsonObject) EventHandlerSpecification(com.continuuity.weave.api.EventHandlerSpecification) DefaultEventHandlerSpecification(com.continuuity.weave.internal.DefaultEventHandlerSpecification) RuntimeSpecification(com.continuuity.weave.api.RuntimeSpecification) DefaultWeaveSpecification(com.continuuity.weave.internal.DefaultWeaveSpecification)

Example 74 with TypeToken

use of com.google.common.reflect.TypeToken in project azure-sdk-for-java by Azure.

the class AccountsImpl method updateWithServiceResponseAsync.

/**
     * Updates the Data Lake Analytics account object specified by the accountName with the contents of the account object.
     *
     * @param resourceGroupName The name of the Azure resource group that contains the Data Lake Analytics account.
     * @param accountName The name of the Data Lake Analytics account to update.
     * @throws IllegalArgumentException thrown if parameters fail the validation
     * @return the observable for the request
     */
public Observable<ServiceResponse<DataLakeAnalyticsAccount>> updateWithServiceResponseAsync(String resourceGroupName, String accountName) {
    if (resourceGroupName == null) {
        throw new IllegalArgumentException("Parameter resourceGroupName is required and cannot be null.");
    }
    if (accountName == null) {
        throw new IllegalArgumentException("Parameter accountName is required and cannot be null.");
    }
    if (this.client.subscriptionId() == null) {
        throw new IllegalArgumentException("Parameter this.client.subscriptionId() is required and cannot be null.");
    }
    if (this.client.apiVersion() == null) {
        throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null.");
    }
    final DataLakeAnalyticsAccountUpdateParameters parameters = null;
    Observable<Response<ResponseBody>> observable = service.update(resourceGroupName, accountName, this.client.subscriptionId(), parameters, this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent());
    return client.getAzureClient().getPutOrPatchResultAsync(observable, new TypeToken<DataLakeAnalyticsAccount>() {
    }.getType());
}
Also used : Response(retrofit2.Response) ServiceResponse(com.microsoft.rest.ServiceResponse) DataLakeAnalyticsAccountUpdateParameters(com.microsoft.azure.management.datalake.analytics.models.DataLakeAnalyticsAccountUpdateParameters) TypeToken(com.google.common.reflect.TypeToken)

Example 75 with TypeToken

use of com.google.common.reflect.TypeToken in project azure-sdk-for-java by Azure.

the class VirtualMachineScaleSetsInner method powerOffWithServiceResponseAsync.

/**
     * Power off (stop) one or more virtual machines in a VM scale set. Note that resources are still attached and you are getting charged for the resources. Instead, use deallocate to release resources and avoid charges.
     *
     * @param resourceGroupName The name of the resource group.
     * @param vmScaleSetName The name of the VM scale set.
     * @throws IllegalArgumentException thrown if parameters fail the validation
     * @return the observable for the request
     */
public Observable<ServiceResponse<OperationStatusResponseInner>> powerOffWithServiceResponseAsync(String resourceGroupName, String vmScaleSetName) {
    if (resourceGroupName == null) {
        throw new IllegalArgumentException("Parameter resourceGroupName is required and cannot be null.");
    }
    if (vmScaleSetName == null) {
        throw new IllegalArgumentException("Parameter vmScaleSetName is required and cannot be null.");
    }
    if (this.client.subscriptionId() == null) {
        throw new IllegalArgumentException("Parameter this.client.subscriptionId() is required and cannot be null.");
    }
    final String apiVersion = "2016-04-30-preview";
    final String instanceIdsConverted = null;
    VirtualMachineScaleSetVMInstanceIDs vmInstanceIDs = new VirtualMachineScaleSetVMInstanceIDs();
    vmInstanceIDs.withInstanceIds(null);
    Observable<Response<ResponseBody>> observable = service.powerOff(resourceGroupName, vmScaleSetName, this.client.subscriptionId(), apiVersion, this.client.acceptLanguage(), vmInstanceIDs, this.client.userAgent());
    return client.getAzureClient().getPostOrDeleteResultAsync(observable, new TypeToken<OperationStatusResponseInner>() {
    }.getType());
}
Also used : Response(retrofit2.Response) ServiceResponse(com.microsoft.rest.ServiceResponse) VirtualMachineScaleSetVMInstanceIDs(com.microsoft.azure.management.compute.VirtualMachineScaleSetVMInstanceIDs) TypeToken(com.google.common.reflect.TypeToken)

Aggregations

TypeToken (com.google.common.reflect.TypeToken)135 Test (org.junit.Test)60 HttpResponse (co.cask.common.http.HttpResponse)26 URL (java.net.URL)24 ServiceResponse (com.microsoft.rest.ServiceResponse)22 Response (retrofit2.Response)22 BinaryEncoder (co.cask.cdap.common.io.BinaryEncoder)18 BinaryDecoder (co.cask.cdap.common.io.BinaryDecoder)17 PipedInputStream (java.io.PipedInputStream)17 PipedOutputStream (java.io.PipedOutputStream)17 ReflectionDatumReader (co.cask.cdap.internal.io.ReflectionDatumReader)16 List (java.util.List)16 Map (java.util.Map)11 ImmutableList (com.google.common.collect.ImmutableList)9 Type (java.lang.reflect.Type)9 AbstractViewTest (org.corfudb.runtime.view.AbstractViewTest)9 NotFoundException (co.cask.cdap.common.NotFoundException)8 VirtualMachineScaleSetVMInstanceIDs (com.microsoft.azure.management.compute.VirtualMachineScaleSetVMInstanceIDs)8 Gson (com.google.gson.Gson)7 JsonObject (com.google.gson.JsonObject)7