Search in sources :

Example 1 with GetEntityResponse

use of org.bedework.calfacade.responses.GetEntityResponse in project bw-calendar-engine by Bedework.

the class BwIndexEsImpl method fetchLocationByKey.

@Override
public GetEntityResponse<BwLocation> fetchLocationByKey(final String name, final String val) {
    final GetEntityResponse<BwLocation> resp = new GetEntityResponse<>();
    try {
        final SearchHit hit = fetchEntity(docTypeLocation, getFilters(null).locationKeyFilter(name, val));
        if (hit == null) {
            return notFound(resp);
        }
        final EntityBuilder eb = getEntityBuilder(hit.sourceAsMap());
        final BwLocation loc = eb.makeLocation();
        if (loc == null) {
            return notFound(resp);
        }
        resp.setEntity(loc);
        return resp;
    } catch (final CalFacadeException cfe) {
        return errorReturn(resp, cfe);
    }
}
Also used : BwLocation(org.bedework.calfacade.BwLocation) SearchHit(org.elasticsearch.search.SearchHit) GetEntityResponse(org.bedework.calfacade.responses.GetEntityResponse) CalFacadeException(org.bedework.calfacade.exc.CalFacadeException)

Example 2 with GetEntityResponse

use of org.bedework.calfacade.responses.GetEntityResponse in project bw-calendar-engine by Bedework.

the class BwIndexEsImpl method fetchEvent.

@Override
public GetEntityResponse<EventInfo> fetchEvent(final String href) throws CalFacadeException {
    final GetEntityResponse<EventInfo> resp = new GetEntityResponse<>();
    final String recurrenceId;
    final String hrefNorid;
    // Check validity
    final int pos = href.lastIndexOf("/");
    if (pos < 0) {
        throw new RuntimeException("Bad href: " + href);
    }
    final int fragPos = href.lastIndexOf("#");
    if (fragPos < pos) {
        hrefNorid = href;
        recurrenceId = null;
    } else {
        hrefNorid = href.substring(0, fragPos);
        recurrenceId = href.substring(fragPos + 1);
    }
    final FilterBuilder fltr = getFilters(null).singleEventFilter(href, recurrenceId);
    final SearchHit hit = fetchEntity(docTypeEvent, fltr);
    if (hit == null) {
        return notFound(resp);
    }
    final EntityBuilder eb = getEntityBuilder(hit.sourceAsMap());
    final EventInfo ei = eb.makeEvent(hit.getId(), false);
    if (ei == null) {
        return notFound(resp);
    }
    final BwEvent ev = ei.getEvent();
    final Acl.CurrentAccess ca = accessCheck.checkAccess(ev, privRead, true);
    if ((ca == null) || !ca.getAccessAllowed()) {
        return notFound(resp);
    }
    ei.setCurrentAccess(ca);
    if (ev.getRecurrenceId() != null) {
        // Single instance
        resp.setEntity(ei);
        return resp;
    }
    addOverrides(resp, idxpars.getUserIndexName(), ei);
    return resp;
}
Also used : EventInfo(org.bedework.calfacade.svc.EventInfo) SearchHit(org.elasticsearch.search.SearchHit) TermFilterBuilder(org.elasticsearch.index.query.TermFilterBuilder) FilterBuilder(org.elasticsearch.index.query.FilterBuilder) BwEvent(org.bedework.calfacade.BwEvent) Acl(org.bedework.access.Acl) GetEntityResponse(org.bedework.calfacade.responses.GetEntityResponse)

Aggregations

GetEntityResponse (org.bedework.calfacade.responses.GetEntityResponse)2 SearchHit (org.elasticsearch.search.SearchHit)2 Acl (org.bedework.access.Acl)1 BwEvent (org.bedework.calfacade.BwEvent)1 BwLocation (org.bedework.calfacade.BwLocation)1 CalFacadeException (org.bedework.calfacade.exc.CalFacadeException)1 EventInfo (org.bedework.calfacade.svc.EventInfo)1 FilterBuilder (org.elasticsearch.index.query.FilterBuilder)1 TermFilterBuilder (org.elasticsearch.index.query.TermFilterBuilder)1