Skip to content

Commit

Permalink
Merge pull request #940 from MetadataConsulting/bug/cannot-create-draft
Browse files Browse the repository at this point in the history
ignoring attempts to index nulls
  • Loading branch information
davidmilward authored Feb 21, 2017
2 parents c5f808a + ae6974e commit bacbc07
Showing 1 changed file with 22 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -344,11 +344,13 @@ class ElasticSearchService implements SearchCatalogue {

@Override
Observable<Boolean> index(Object object) {
// TODO: investigate why the object can be null
index IndexingSession.create(), just(object)
}

@Override
Observable<Boolean> index(Iterable<Object> resource) {
// TODO: investigate why the iterable can contain null values
index IndexingSession.create(), from(resource)
}

Expand Down Expand Up @@ -398,20 +400,25 @@ class ElasticSearchService implements SearchCatalogue {
}

private Observable<Boolean> unindexInternal(IndexingSession session, Object element) {
return from(getIndices(element)).flatMap { idx ->
indexExists(session, just(idx)).flatMap { response ->
if (response.exists) {
return RxElastic.from(client.prepareDelete(idx, getTypeName(getEntityClass(element)), "${element.getId()}")).map {
log.debug "Unindexed $element from $idx"
it.found
}.onErrorReturn { error ->
log.debug "Exception unindexing $element: $error"
return false
try {
return from(getIndices(element)).flatMap { idx ->
indexExists(session, just(idx)).flatMap { response ->
if (response.exists) {
return RxElastic.from(client.prepareDelete(idx, getTypeName(getEntityClass(element)), "${element.getId()}")).map {
log.debug "Unindexed $element from $idx"
it.found
}.onErrorReturn { error ->
log.debug "Exception unindexing $element: $error"
return false
}
}
return just(true)
}
return just(true)
}
} catch (UnsupportedOperationException e) {
return Observable.error(e)
}

}

@Override
Expand Down Expand Up @@ -549,6 +556,7 @@ class ElasticSearchService implements SearchCatalogue {
if (DataModelPolicy.isAssignableFrom(clazz)) {
return DataModelPolicy
}
log.warn("Object $it doesn't belong to any group. Entity class resolved as Object")
return clazz
} flatMap { group ->
if (group.key == CatalogueElement) {
Expand All @@ -562,7 +570,10 @@ class ElasticSearchService implements SearchCatalogue {
if (group.key in [RelationshipType, DataModelPolicy]) {
return group
}
throw new UnsupportedOperationException("Not Yet Implemented for '$group.key': ${group.toList().toBlocking().first()}")
if (group.key == Object) {
return Observable.empty()
}
return Observable.error(new UnsupportedOperationException("Not Yet Implemented for '$group.key'"))
} flatMap { entity ->
Class clazz = getEntityClass(entity)
ImmutableSet<String> indices = getIndices(entity)
Expand Down

0 comments on commit bacbc07

Please sign in to comment.