Search in sources :

Example 11 with NotSupportedException

use of javax.ws.rs.NotSupportedException in project openremote by openremote.

the class AssetDatapointResourceImpl method getDatapoints.

@Override
public ValueDatapoint<?>[] getDatapoints(@BeanParam RequestParams requestParams, String assetId, String attributeName, DatapointInterval interval, Integer stepSize, long fromTimestamp, long toTimestamp) {
    try {
        if (isRestrictedUser() && !assetStorageService.isUserAsset(getUserId(), assetId)) {
            throw new WebApplicationException(Response.Status.FORBIDDEN);
        }
        Asset<?> asset = assetStorageService.find(assetId, true);
        if (asset == null) {
            throw new WebApplicationException(Response.Status.NOT_FOUND);
        }
        if (!isTenantActiveAndAccessible(asset.getRealm())) {
            LOG.info("Forbidden access for user '" + getUsername() + "': " + asset);
            throw new WebApplicationException(Response.Status.FORBIDDEN);
        }
        Attribute<?> attribute = asset.getAttribute(attributeName).orElseThrow(() -> new WebApplicationException(Response.Status.NOT_FOUND));
        return assetDatapointService.getValueDatapoints(assetId, attribute, interval, stepSize, LocalDateTime.ofInstant(Instant.ofEpochMilli(fromTimestamp), ZoneId.systemDefault()), LocalDateTime.ofInstant(Instant.ofEpochMilli(toTimestamp), ZoneId.systemDefault()));
    } catch (IllegalStateException ex) {
        throw new BadRequestException(ex);
    } catch (UnsupportedOperationException ex) {
        throw new NotSupportedException(ex);
    }
}
Also used : WebApplicationException(javax.ws.rs.WebApplicationException) BadRequestException(javax.ws.rs.BadRequestException) NotSupportedException(javax.ws.rs.NotSupportedException)

Example 12 with NotSupportedException

use of javax.ws.rs.NotSupportedException in project syncope by apache.

the class ReportRestClient method bulkAction.

public BulkActionResult bulkAction(final BulkAction action) {
    BulkActionResult result = new BulkActionResult();
    switch(action.getType()) {
        case DELETE:
            for (String target : action.getTargets()) {
                delete(target);
                result.getResults().put(target, BulkActionResult.Status.SUCCESS);
            }
            break;
        case EXECUTE:
            for (String target : action.getTargets()) {
                startExecution(target, null);
                result.getResults().put(target, BulkActionResult.Status.SUCCESS);
            }
            break;
        default:
            throw new NotSupportedException(action.getType().name());
    }
    return result;
}
Also used : BulkActionResult(org.apache.syncope.common.lib.to.BulkActionResult) NotSupportedException(javax.ws.rs.NotSupportedException)

Example 13 with NotSupportedException

use of javax.ws.rs.NotSupportedException in project openremote by openremote.

the class AssetDatapointResourceImpl method getDatapointPeriod.

@Override
public DatapointPeriod getDatapointPeriod(RequestParams requestParams, String assetId, String attributeName) {
    try {
        if (isRestrictedUser() && !assetStorageService.isUserAsset(getUserId(), assetId)) {
            throw new WebApplicationException(Response.Status.FORBIDDEN);
        }
        Asset<?> asset = assetStorageService.find(assetId, true);
        if (asset == null) {
            throw new WebApplicationException(Response.Status.NOT_FOUND);
        }
        if (!isTenantActiveAndAccessible(asset.getRealm())) {
            LOG.info("Forbidden access for user '" + getUsername() + "': " + asset);
            throw new WebApplicationException(Response.Status.FORBIDDEN);
        }
        Attribute<?> attribute = asset.getAttribute(attributeName).orElseThrow(() -> new WebApplicationException(Response.Status.NOT_FOUND));
        return assetDatapointService.getDatapointPeriod(assetId, attributeName);
    } catch (IllegalStateException ex) {
        throw new BadRequestException(ex);
    } catch (UnsupportedOperationException ex) {
        throw new NotSupportedException(ex);
    }
}
Also used : WebApplicationException(javax.ws.rs.WebApplicationException) BadRequestException(javax.ws.rs.BadRequestException) NotSupportedException(javax.ws.rs.NotSupportedException)

Example 14 with NotSupportedException

use of javax.ws.rs.NotSupportedException in project dropwizard by dropwizard.

the class IllegalStateExceptionMapperTest method handlesFormParamContentTypeError.

@Test
void handlesFormParamContentTypeError() {
    final Response reponse = mapper.toResponse(new IllegalStateException(LocalizationMessages.FORM_PARAM_CONTENT_TYPE_ERROR()));
    assertThat(reponse.getStatusInfo()).isEqualTo(UNSUPPORTED_MEDIA_TYPE);
    assertThat(reponse.getEntity()).isInstanceOf(ErrorMessage.class);
    assertThat(((ErrorMessage) reponse.getEntity()).getMessage()).isEqualTo(new NotSupportedException().getLocalizedMessage());
}
Also used : Response(javax.ws.rs.core.Response) NotSupportedException(javax.ws.rs.NotSupportedException) Test(org.junit.jupiter.api.Test)

Aggregations

NotSupportedException (javax.ws.rs.NotSupportedException)14 WebApplicationException (javax.ws.rs.WebApplicationException)8 MediaType (javax.ws.rs.core.MediaType)5 Language (com.liferay.apio.architect.language.Language)4 RequestInfo (com.liferay.apio.architect.request.RequestInfo)4 Embedded (com.liferay.apio.architect.response.control.Embedded)4 Fields (com.liferay.apio.architect.response.control.Fields)4 ServerURL (com.liferay.apio.architect.url.ServerURL)4 ProviderManager (com.liferay.apio.architect.wiring.osgi.manager.ProviderManager)4 IOException (java.io.IOException)4 OutputStream (java.io.OutputStream)4 OutputStreamWriter (java.io.OutputStreamWriter)4 PrintWriter (java.io.PrintWriter)4 Annotation (java.lang.annotation.Annotation)4 Type (java.lang.reflect.Type)4 StandardCharsets (java.nio.charset.StandardCharsets)4 Collections (java.util.Collections)4 Locale (java.util.Locale)4 Optional (java.util.Optional)4 HttpServletRequest (javax.servlet.http.HttpServletRequest)4