Search in sources :

Example 1 with Put

use of org.restlet.resource.Put in project pinot by linkedin.

the class PinotTenantRestletResource method put.

/*
   * For tenant update
   */
@Override
@Put("json")
public Representation put(Representation entity) {
    StringRepresentation presentation;
    try {
        final Tenant tenant = _objectMapper.readValue(ByteStreams.toByteArray(entity.getStream()), Tenant.class);
        presentation = updateTenant(tenant);
    } catch (final Exception e) {
        presentation = exceptionToStringRepresentation(e);
        LOGGER.error("Caught exception while updating tenant ", e);
        ControllerRestApplication.getControllerMetrics().addMeteredGlobalValue(ControllerMeter.CONTROLLER_TABLE_TENANT_UPDATE_ERROR, 1L);
        setStatus(Status.SERVER_ERROR_INTERNAL);
    }
    return presentation;
}
Also used : Tenant(com.linkedin.pinot.common.config.Tenant) StringRepresentation(org.restlet.representation.StringRepresentation) JSONException(org.json.JSONException) Put(org.restlet.resource.Put)

Example 2 with Put

use of org.restlet.resource.Put in project OpenAM by OpenRock.

the class ResourceSetRegistrationEndpoint method updateResourceSet.

@Put
public Representation updateResourceSet(JsonRepresentation entity) throws NotFoundException, ServerException, BadRequestException {
    if (!isConditionalRequest()) {
        throw new ResourceException(512, "precondition_failed", "Require If-Match header to update Resource Set", null);
    }
    final Map<String, Object> resourceSetDescriptionAttributes = validator.validate(toMap(entity));
    final String resourceSetId = getResourceSetId();
    ResourceSetStore store = providerSettingsFactory.get(requestFactory.create(getRequest())).getResourceSetStore();
    ResourceSetDescription resourceSetDescription = store.read(resourceSetId, getResourceOwnerId()).update(resourceSetDescriptionAttributes);
    JsonValue labels = resourceSetDescription.getDescription().get(OAuth2Constants.ResourceSets.LABELS);
    resourceSetDescription.getDescription().remove(OAuth2Constants.ResourceSets.LABELS);
    store.update(resourceSetDescription);
    if (labels.isNotNull()) {
        resourceSetDescription.getDescription().add(OAuth2Constants.ResourceSets.LABELS, labels.asSet());
    } else {
        resourceSetDescription.getDescription().add(OAuth2Constants.ResourceSets.LABELS, new HashSet<String>());
    }
    labelRegistration.updateLabelsForExistingResourceSet(resourceSetDescription);
    return createJsonResponse(resourceSetDescription, false, true);
}
Also used : ResourceSetStore(org.forgerock.oauth2.resources.ResourceSetStore) JsonValue(org.forgerock.json.JsonValue) ResourceException(org.restlet.resource.ResourceException) ResourceSetDescription(org.forgerock.oauth2.resources.ResourceSetDescription) Put(org.restlet.resource.Put)

Aggregations

Put (org.restlet.resource.Put)2 Tenant (com.linkedin.pinot.common.config.Tenant)1 JsonValue (org.forgerock.json.JsonValue)1 ResourceSetDescription (org.forgerock.oauth2.resources.ResourceSetDescription)1 ResourceSetStore (org.forgerock.oauth2.resources.ResourceSetStore)1 JSONException (org.json.JSONException)1 StringRepresentation (org.restlet.representation.StringRepresentation)1 ResourceException (org.restlet.resource.ResourceException)1