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);
}
}
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;
}
Aggregations