use of com.enonic.xp.repo.impl.StorageSource in project xp by enonic.
the class StorageDaoImpl method store.
@Override
public String store(final StoreRequest request) {
final StorageSource settings = request.getSettings();
final IndexRequest indexRequest = Requests.indexRequest().index(settings.getStorageName().getName()).type(settings.getStorageType().getName()).source(XContentBuilderFactory.create(request)).id(request.getId()).refresh(request.isForceRefresh());
if (request.getRouting() != null) {
indexRequest.routing(request.getRouting());
}
if (request.getParent() != null) {
indexRequest.parent(request.getParent());
}
return doStore(indexRequest, request.getTimeout());
}
use of com.enonic.xp.repo.impl.StorageSource in project xp by enonic.
the class StorageDaoImpl method getByIds.
@Override
public GetResults getByIds(final GetByIdsRequest requests) {
if (requests.getRequests().isEmpty()) {
return new GetResults();
}
final MultiGetRequestBuilder multiGetRequestBuilder = new MultiGetRequestBuilder(this.client, MultiGetAction.INSTANCE).setPreference(SearchPreference.LOCAL.getName());
for (final GetByIdRequest request : requests.getRequests()) {
final StorageSource storageSource = request.getStorageSource();
final MultiGetRequest.Item item = new MultiGetRequest.Item(storageSource.getStorageName().getName(), storageSource.getStorageType().getName(), request.getId());
if (request.getReturnFields().isNotEmpty()) {
item.fields(request.getReturnFields().getReturnFieldNames());
}
if (request.getRouting() != null) {
item.routing(request.getRouting());
}
multiGetRequestBuilder.add(item);
}
final MultiGetResponse multiGetItemResponses = this.client.multiGet(multiGetRequestBuilder.request()).actionGet();
return GetResultsFactory.create(multiGetItemResponses);
}
use of com.enonic.xp.repo.impl.StorageSource in project xp by enonic.
the class StorageDaoImpl method delete.
@Override
public void delete(final DeleteRequests requests) {
final StorageSource settings = requests.getSettings();
for (final String id : requests.getIds()) {
try {
final org.elasticsearch.action.delete.DeleteRequest request = new DeleteRequestBuilder(this.client, DeleteAction.INSTANCE).setIndex(settings.getStorageName().getName()).setType(settings.getStorageType().getName()).setRefresh(requests.isForceRefresh()).setId(id).setRouting(// TODO Java10
id).request();
this.client.delete(request).actionGet(requests.getTimeoutAsString());
} catch (ClusterBlockException e) {
throw new NodeStorageException("Cannot delete node " + id + ", Repository in 'READ-ONLY mode'");
} catch (Exception e) {
throw new NodeStorageException("Cannot delete node " + id, e);
}
}
}
use of com.enonic.xp.repo.impl.StorageSource in project xp by enonic.
the class StorageDaoImpl method getById.
@Override
public GetResult getById(final GetByIdRequest request) {
final StorageSource storageSource = request.getStorageSource();
final GetRequest getRequest = new GetRequest(storageSource.getStorageName().getName()).type(storageSource.getStorageType().getName()).preference(request.getSearchPreference().getName()).id(request.getId());
if (request.getReturnFields().isNotEmpty()) {
getRequest.fields(request.getReturnFields().getReturnFieldNames());
}
if (request.getRouting() != null) {
getRequest.routing(request.getRouting());
}
final GetResponse getResponse = client.get(getRequest).actionGet(request.getTimeout());
return GetResultFactory.create(getResponse);
}
use of com.enonic.xp.repo.impl.StorageSource in project xp by enonic.
the class StorageDaoImpl method delete.
@Override
public boolean delete(final DeleteRequest request) {
final StorageSource settings = request.getSettings();
final String id = request.getId();
final DeleteRequestBuilder builder = new DeleteRequestBuilder(this.client, DeleteAction.INSTANCE).setId(id).setIndex(settings.getStorageName().getName()).setType(settings.getStorageType().getName()).setRefresh(request.isForceRefresh());
final DeleteResponse deleteResponse;
try {
deleteResponse = this.client.delete(builder.request()).actionGet(request.getTimeoutAsString());
} catch (ClusterBlockException e) {
throw new NodeStorageException("Cannot delete node " + id + ", Repository in 'READ-ONLY mode'");
} catch (Exception e) {
throw new NodeStorageException("Cannot delete node " + id, e);
}
return deleteResponse.isFound();
}
Aggregations