@Test public void objectExistInOfferNotFound() throws Exception { when(mock.head()).thenReturn(Response.status(Status.NOT_FOUND).build()); final StorageObjectRequest request = new StorageObjectRequest(tenant, DataCategory.OBJECT.getFolder(), "guid"); try (Connection connection = driver.connect(offer.getId())) { final boolean found = connection.objectExistsInOffer(request); assertFalse(found); } catch (final StorageDriverException exc) { fail("Ne exception expected"); } }
@Override public boolean objectExistsInOffer(StorageObjectRequest request) throws StorageDriverException { ParametersChecker.checkParameter(REQUEST_IS_A_MANDATORY_PARAMETER, request); ParametersChecker.checkParameter(GUID_IS_A_MANDATORY_PARAMETER, request.getGuid()); ParametersChecker.checkParameter(TENANT_IS_A_MANDATORY_PARAMETER, request.getTenantId()); VitamRequestBuilder requestBuilder = head() .withPath(OBJECTS_PATH + "/" + DataCategory.getByFolder(request.getType()) + "/" + request.getGuid()) .withHeader(GlobalDataRest.X_TENANT_ID, request.getTenantId()) .withJsonAccept(); try (Response response = make(requestBuilder)) { final Status status = fromStatusCode(response.getStatus()); switch (status) { case OK: case NO_CONTENT: return true; case NOT_FOUND: return false; case BAD_REQUEST: LOGGER.error(BAD_REQUEST_ERROR_MESSAGE); throw new StorageDriverPreconditionFailedException(getDriverName(), BAD_REQUEST_ERROR_MESSAGE); default: LOGGER.error(status.getReasonPhrase()); throw new StorageDriverException(getDriverName(), status.getReasonPhrase(), true); } } catch (final VitamClientInternalException e) { LOGGER.error(VitamCodeHelper.getLogMessage(VitamCode.STORAGE_TECHNICAL_INTERNAL_ERROR), e); throw new StorageDriverException(getDriverName(), true, e); } }
ConnectionImpl extends AbstractConnection { @Override public boolean objectExistsInOffer(StorageObjectRequest request) throws StorageDriverException { ParametersChecker.checkParameter(REQUEST_IS_A_MANDATORY_PARAMETER, request); ParametersChecker.checkParameter(GUID_IS_A_MANDATORY_PARAMETER, request.getGuid()); ParametersChecker.checkParameter(TENANT_IS_A_MANDATORY_PARAMETER, request.getTenantId()); VitamRequestBuilder requestBuilder = head() .withPath(OBJECTS_PATH + "/" + DataCategory.getByFolder(request.getType()) + "/" + request.getGuid()) .withHeader(GlobalDataRest.X_TENANT_ID, request.getTenantId()) .withJsonAccept(); try (Response response = make(requestBuilder)) { final Status status = fromStatusCode(response.getStatus()); switch (status) { case OK: case NO_CONTENT: return true; case NOT_FOUND: return false; case BAD_REQUEST: LOGGER.error(BAD_REQUEST_ERROR_MESSAGE); throw new StorageDriverPreconditionFailedException(getDriverName(), BAD_REQUEST_ERROR_MESSAGE); default: LOGGER.error(status.getReasonPhrase()); throw new StorageDriverException(getDriverName(), status.getReasonPhrase(), true); } } catch (final VitamClientInternalException e) { LOGGER.error(VitamCodeHelper.getLogMessage(VitamCode.STORAGE_TECHNICAL_INTERNAL_ERROR), e); throw new StorageDriverException(getDriverName(), true, e); } } }
ConnectionImpl extends AbstractConnection { @Override public boolean objectExistsInOffer(StorageObjectRequest request) throws StorageDriverException { ParametersChecker.checkParameter(REQUEST_IS_A_MANDATORY_PARAMETER, request); ParametersChecker.checkParameter(GUID_IS_A_MANDATORY_PARAMETER, request.getGuid()); ParametersChecker.checkParameter(TENANT_IS_A_MANDATORY_PARAMETER, request.getTenantId()); VitamRequestBuilder requestBuilder = head() .withPath(OBJECTS_PATH + "/" + DataCategory.getByFolder(request.getType()) + "/" + request.getGuid()) .withHeader(GlobalDataRest.X_TENANT_ID, request.getTenantId()) .withJsonAccept(); try (Response response = make(requestBuilder)) { final Status status = fromStatusCode(response.getStatus()); switch (status) { case OK: case NO_CONTENT: return true; case NOT_FOUND: return false; case BAD_REQUEST: LOGGER.error(BAD_REQUEST_ERROR_MESSAGE); throw new StorageDriverPreconditionFailedException(getDriverName(), BAD_REQUEST_ERROR_MESSAGE); default: LOGGER.error(status.getReasonPhrase()); throw new StorageDriverException(getDriverName(), status.getReasonPhrase(), true); } } catch (final VitamClientInternalException e) { LOGGER.error(VitamCodeHelper.getLogMessage(VitamCode.STORAGE_TECHNICAL_INTERNAL_ERROR), e); throw new StorageDriverException(getDriverName(), true, e); } } ConnectionImpl(String driverName, VitamClientFactoryInterface<? extends AbstractConnection> factory); }
ConnectionImpl extends AbstractConnection { @Override public boolean objectExistsInOffer(StorageObjectRequest request) throws StorageDriverException { ParametersChecker.checkParameter(REQUEST_IS_A_MANDATORY_PARAMETER, request); ParametersChecker.checkParameter(GUID_IS_A_MANDATORY_PARAMETER, request.getGuid()); ParametersChecker.checkParameter(TENANT_IS_A_MANDATORY_PARAMETER, request.getTenantId()); VitamRequestBuilder requestBuilder = head() .withPath(OBJECTS_PATH + "/" + DataCategory.getByFolder(request.getType()) + "/" + request.getGuid()) .withHeader(GlobalDataRest.X_TENANT_ID, request.getTenantId()) .withJsonAccept(); try (Response response = make(requestBuilder)) { final Status status = fromStatusCode(response.getStatus()); switch (status) { case OK: case NO_CONTENT: return true; case NOT_FOUND: return false; case BAD_REQUEST: LOGGER.error(BAD_REQUEST_ERROR_MESSAGE); throw new StorageDriverPreconditionFailedException(getDriverName(), BAD_REQUEST_ERROR_MESSAGE); default: LOGGER.error(status.getReasonPhrase()); throw new StorageDriverException(getDriverName(), status.getReasonPhrase(), true); } } catch (final VitamClientInternalException e) { LOGGER.error(VitamCodeHelper.getLogMessage(VitamCode.STORAGE_TECHNICAL_INTERNAL_ERROR), e); throw new StorageDriverException(getDriverName(), true, e); } } ConnectionImpl(String driverName, VitamClientFactoryInterface<? extends AbstractConnection> factory); @Override StorageCapacityResult getStorageCapacity(Integer tenantId); @Override StorageGetResult getObject(StorageObjectRequest request); @Override RequestResponse<TapeReadRequestReferentialEntity> createReadOrderRequest(StorageObjectRequest request); @Override RequestResponse<TapeReadRequestReferentialEntity> getReadOrderRequest(String readOrderRequestId, int tenant); @Override void removeReadOrderRequest(String readOrderRequestId, int tenant); @Override StoragePutResult putObject(StoragePutRequest request); @Override StorageBulkPutResult bulkPutObjects(StorageBulkPutRequest request); @Override StorageRemoveResult removeObject(StorageRemoveRequest request); @Override boolean objectExistsInOffer(StorageObjectRequest request); @Override StorageMetadataResult getMetadatas(StorageGetMetadataRequest request); @Override CloseableIterator<ObjectEntry> listObjects(StorageListRequest request); @Override RequestResponse<OfferLog> getOfferLogs(StorageOfferLogRequest storageGetOfferLogRequest); }
ConnectionImpl extends AbstractConnection { @Override public boolean objectExistsInOffer(StorageObjectRequest request) throws StorageDriverException { ParametersChecker.checkParameter(REQUEST_IS_A_MANDATORY_PARAMETER, request); ParametersChecker.checkParameter(GUID_IS_A_MANDATORY_PARAMETER, request.getGuid()); ParametersChecker.checkParameter(TENANT_IS_A_MANDATORY_PARAMETER, request.getTenantId()); VitamRequestBuilder requestBuilder = head() .withPath(OBJECTS_PATH + "/" + DataCategory.getByFolder(request.getType()) + "/" + request.getGuid()) .withHeader(GlobalDataRest.X_TENANT_ID, request.getTenantId()) .withJsonAccept(); try (Response response = make(requestBuilder)) { final Status status = fromStatusCode(response.getStatus()); switch (status) { case OK: case NO_CONTENT: return true; case NOT_FOUND: return false; case BAD_REQUEST: LOGGER.error(BAD_REQUEST_ERROR_MESSAGE); throw new StorageDriverPreconditionFailedException(getDriverName(), BAD_REQUEST_ERROR_MESSAGE); default: LOGGER.error(status.getReasonPhrase()); throw new StorageDriverException(getDriverName(), status.getReasonPhrase(), true); } } catch (final VitamClientInternalException e) { LOGGER.error(VitamCodeHelper.getLogMessage(VitamCode.STORAGE_TECHNICAL_INTERNAL_ERROR), e); throw new StorageDriverException(getDriverName(), true, e); } } ConnectionImpl(String driverName, VitamClientFactoryInterface<? extends AbstractConnection> factory); @Override StorageCapacityResult getStorageCapacity(Integer tenantId); @Override StorageGetResult getObject(StorageObjectRequest request); @Override RequestResponse<TapeReadRequestReferentialEntity> createReadOrderRequest(StorageObjectRequest request); @Override RequestResponse<TapeReadRequestReferentialEntity> getReadOrderRequest(String readOrderRequestId, int tenant); @Override void removeReadOrderRequest(String readOrderRequestId, int tenant); @Override StoragePutResult putObject(StoragePutRequest request); @Override StorageBulkPutResult bulkPutObjects(StorageBulkPutRequest request); @Override StorageRemoveResult removeObject(StorageRemoveRequest request); @Override boolean objectExistsInOffer(StorageObjectRequest request); @Override StorageMetadataResult getMetadatas(StorageGetMetadataRequest request); @Override CloseableIterator<ObjectEntry> listObjects(StorageListRequest request); @Override RequestResponse<OfferLog> getOfferLogs(StorageOfferLogRequest storageGetOfferLogRequest);  }