class BusinessObjectDataInitiateRestoreHelperServiceImpl implements BusinessObjectDataInitiateRestoreHelperService {

    protected StorageUnitEntity getStorageUnit(BusinessObjectDataEntity businessObjectDataEntity)
    {
        // Retrieve all S3 storage units for this business object data.
        List<StorageUnitEntity> s3StorageUnitEntities =
            storageUnitDao.getStorageUnitsByStoragePlatformAndBusinessObjectData(StoragePlatformEntity.S3, businessObjectDataEntity);

        // Validate that business object data has at least one S3 storage unit.
        if (CollectionUtils.isEmpty(s3StorageUnitEntities))
        {
            throw new IllegalArgumentException(String.format("Business object data has no S3 storage unit. Business object data: {%s}",
                businessObjectDataHelper.businessObjectDataEntityAltKeyToString(businessObjectDataEntity)));
        }

        // Validate that this business object data has no multiple S3 storage units.
        if (CollectionUtils.size(s3StorageUnitEntities) > 1)
        {
            throw new IllegalArgumentException(String
                .format("Business object data has multiple (%s) %s storage units. Business object data: {%s}", s3StorageUnitEntities.size(),
                    StoragePlatformEntity.S3, businessObjectDataHelper.businessObjectDataEntityAltKeyToString(businessObjectDataEntity)));
        }

        // Get the S3 storage unit.
        StorageUnitEntity storageUnitEntity = s3StorageUnitEntities.get(0);

        // Get the storage unit status code.
        String storageUnitStatus = storageUnitEntity.getStatus().getCode();

        // Validate that this business object data has its S3 storage unit in "ARCHIVED" state.
        if (!StorageUnitStatusEntity.ARCHIVED.equals(storageUnitStatus))
        {
            // Get the storage name.
            String storageName = storageUnitEntity.getStorage().getName();

            // Fail with a custom error message if the S3 storage unit is already enabled.
            if (StorageUnitStatusEntity.ENABLED.equals(storageUnitStatus))
            {
                throw new IllegalArgumentException(String
                    .format("Business object data is already available in \"%s\" S3 storage. Business object data: {%s}", storageName,
                        businessObjectDataHelper.businessObjectDataEntityAltKeyToString(storageUnitEntity.getBusinessObjectData())));
            }
            // Fail with a custom error message if this business object data is already marked as being restored.
            else if (StorageUnitStatusEntity.RESTORING.equals(storageUnitStatus))
            {
                throw new IllegalArgumentException(String
                    .format("Business object data is already being restored in \"%s\" S3 storage. Business object data: {%s}", storageName,
                        businessObjectDataHelper.businessObjectDataEntityAltKeyToString(storageUnitEntity.getBusinessObjectData())));
            }
            // Else, fail and report the actual S3 storage unit status.
            else
            {
                throw new IllegalArgumentException(String.format("Business object data is not archived. " +
                        "S3 storage unit in \"%s\" storage must have \"%s\" status, but it actually has \"%s\" status. Business object data: {%s}", storageName,
                    StorageUnitStatusEntity.ARCHIVED, storageUnitStatus,
                    businessObjectDataHelper.businessObjectDataEntityAltKeyToString(storageUnitEntity.getBusinessObjectData())));
            }
        }

        return storageUnitEntity;
    }

}