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);
}
}
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;
}
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);
}
}
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());
}
Aggregations