2022-02-04 10:12:15 +01:00
|
|
|
package eu.dnetlib.openaire.dsm.dao;
|
|
|
|
|
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
|
import org.apache.commons.logging.Log;
|
|
|
|
import org.apache.commons.logging.LogFactory;
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
|
|
|
import org.springframework.stereotype.Component;
|
|
|
|
|
2023-03-31 14:53:52 +02:00
|
|
|
import eu.dnetlib.data.objectstore.rmi.ObjectStoreService;
|
|
|
|
import eu.dnetlib.data.objectstore.rmi.ObjectStoreServiceException;
|
2023-04-03 12:22:22 +02:00
|
|
|
import eu.dnetlib.openaire.exporter.exceptions.DsmApiException;
|
2023-03-31 14:53:52 +02:00
|
|
|
|
2022-02-04 10:12:15 +01:00
|
|
|
@Component
|
|
|
|
@ConditionalOnProperty(value = "openaire.exporter.enable.dsm", havingValue = "true")
|
|
|
|
public class ObjectStoreClientImpl implements ObjectStoreClient {
|
|
|
|
|
|
|
|
private static final Log log = LogFactory.getLog(ObjectStoreClientImpl.class);
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
private ObjectStoreService objectStoreService;
|
|
|
|
|
|
|
|
@Override
|
2023-04-03 12:22:22 +02:00
|
|
|
public Long getObjectStoreSize(final String objectStoreId) throws DsmApiException {
|
2022-02-04 10:12:15 +01:00
|
|
|
log.debug("get size for objectStore " + objectStoreId);
|
2023-03-31 14:53:52 +02:00
|
|
|
if (StringUtils.isBlank(objectStoreId)) { return 0L; }
|
2022-02-04 10:12:15 +01:00
|
|
|
try {
|
|
|
|
final long size = objectStoreService.getSize(objectStoreId);
|
|
|
|
log.debug("got objectStore size: " + size);
|
|
|
|
return size;
|
2023-03-31 14:53:52 +02:00
|
|
|
} catch (final ObjectStoreServiceException e) {
|
2023-04-03 12:22:22 +02:00
|
|
|
throw new DsmApiException("unable to get size for objectStore " + objectStoreId);
|
2022-02-04 10:12:15 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|