use of org.bedework.calfacade.BwEventProperty in project bw-calendar-engine by Bedework.
the class CalSvc method changeAccess.
/* ====================================================================
* Access
* ==================================================================== */
/* (non-Javadoc)
* @see org.bedework.calsvci.CalSvcI#changeAccess(org.bedework.calfacade.base.BwShareableDbentity, java.util.Collection)
*/
@Override
public void changeAccess(BwShareableDbentity ent, final Collection<Ace> aces, final boolean replaceAll) throws CalFacadeException {
if (ent instanceof BwCalSuiteWrapper) {
ent = ((BwCalSuiteWrapper) ent).fetchEntity();
}
getCal().changeAccess(ent, aces, replaceAll);
if (ent instanceof BwCalendar) {
final BwCalendar col = (BwCalendar) ent;
if (col.getCalType() == BwCalendar.calTypeInbox) {
// Same access as inbox
final BwCalendar pendingInbox = getCalendarsHandler().getSpecial(BwCalendar.calTypePendingInbox, true);
if (pendingInbox == null) {
warn("Unable to update pending inbox access");
} else {
getCal().changeAccess(pendingInbox, aces, replaceAll);
}
}
((Preferences) getPrefsHandler()).updateAdminPrefs(false, col, null, null, null);
} else if (ent instanceof BwEventProperty) {
((Preferences) getPrefsHandler()).updateAdminPrefs(false, (BwEventProperty) ent);
}
}
use of org.bedework.calfacade.BwEventProperty in project bw-calendar-engine by Bedework.
the class AccessUtil method getAclChars.
/* ====================================================================
* Private methods
* ==================================================================== */
/* If the entity is not a collection we merge the access in with the container
* access then return the merged aces. We do this because we call getPathInfo
* with a collection entity. That method will recurse up to the root.
*
* For a calendar we just use the access for the calendar.
*
* The calendar/container access might be cached in the pathInfoTable.
*/
private char[] getAclChars(final BwShareableDbentity<?> ent) throws CalFacadeException {
if ((!(ent instanceof BwEventProperty)) && (ent instanceof BwShareableContainedDbentity)) {
BwCalendar container;
if (ent instanceof BwCalendar) {
container = (BwCalendar) ent;
} else {
container = getParent((BwShareableContainedDbentity<?>) ent);
}
if (container == null) {
return null;
}
final String path = container.getPath();
CalendarWrapper wcol = (CalendarWrapper) container;
String aclStr;
char[] aclChars = null;
/* Get access for the parent first if we have one */
BwCalendar parent = getParent(wcol);
if (parent != null) {
aclStr = new String(merged(getAclChars(parent), parent.getPath(), wcol.getAccess()));
} else if (wcol.getAccess() != null) {
aclStr = wcol.getAccess();
} else {
// At root
throw new CalFacadeException("Collections must have default access set at root");
}
if (aclStr != null) {
aclChars = aclStr.toCharArray();
}
if (ent instanceof BwCalendar) {
return aclChars;
}
return merged(aclChars, path, ent.getAccess());
}
/* This is a way of making other objects sort of shareable.
* The objects are locations, sponsors and categories.
* (also calsuite)
*
* We store the default access in the owner principal and manipulate that to give
* us some degree of sharing.
*
* In effect, the owner becomes the container for the object.
*/
String aclString = null;
String entAccess = ent.getAccess();
BwPrincipal owner = (BwPrincipal) cb.getPrincipal(ent.getOwnerHref());
if (ent instanceof BwCategory) {
aclString = owner.getCategoryAccess();
} else if (ent instanceof BwLocation) {
aclString = owner.getLocationAccess();
} else if (ent instanceof BwContact) {
aclString = owner.getContactAccess();
}
if (aclString == null) {
if (entAccess == null) {
if (ent.getPublick()) {
return Access.getDefaultPublicAccess().toCharArray();
}
return Access.getDefaultPersonalAccess().toCharArray();
}
return entAccess.toCharArray();
}
if (entAccess == null) {
return aclString.toCharArray();
}
try {
Acl acl = Acl.decode(entAccess.toCharArray());
acl = acl.merge(aclString.toCharArray(), "/owner");
return acl.getEncoded();
} catch (Throwable t) {
throw new CalFacadeException(t);
}
}
use of org.bedework.calfacade.BwEventProperty in project bw-calendar-engine by Bedework.
the class BwIndexEsImpl method reindex.
private void reindex(final ReindexResponse resp, final String indexName, final String docType) {
// Only retrieve masters - we'll query for the overrides
final QueryBuilder qb = getFilters(RecurringRetrievalMode.entityOnly).getAllForReindex(docType);
// 1 minute
final int timeoutMillis = 60000;
final TimeValue tv = new TimeValue(timeoutMillis);
final int batchSize = 100;
final Client cl = getClient(resp);
if (cl == null) {
return;
}
checkUidsMap();
// Start with default index as source
targetIndex = Util.buildPath(false, idxpars.getUserIndexName());
final BulkProcessor bulkProcessor = BulkProcessor.builder(cl, new BulkListener()).setBulkActions(batchSize).setConcurrentRequests(3).setFlushInterval(tv).build();
SearchResponse scrollResp = cl.prepareSearch(targetIndex).setSearchType(SearchType.SCAN).setScroll(tv).setQuery(qb).setSize(batchSize).execute().actionGet();
// Switch to new index
targetIndex = indexName;
// Scroll until no hits are returned
while (true) {
for (final SearchHit hit : scrollResp.getHits().getHits()) {
final String dtype = hit.getType();
resp.incProcessed();
if ((resp.getProcessed() % 250) == 0) {
info("processed " + docType + ": " + resp.getProcessed());
}
if (dtype.equals(docTypeUpdateTracker)) {
continue;
}
resp.getStats().inc(docToType.getOrDefault(dtype, unreachableEntities));
final ReindexResponse.Failure hitResp = new ReindexResponse.Failure();
final Object entity = makeEntity(hitResp, hit, null);
if (entity == null) {
warn("Unable to build entity " + hit.sourceAsString());
resp.incTotalFailed();
if (resp.getTotalFailed() < 50) {
resp.addFailure(hitResp);
}
continue;
}
if (entity instanceof BwShareableDbentity) {
final BwShareableDbentity ent = (BwShareableDbentity) entity;
try {
principal = BwPrincipal.makePrincipal(ent.getOwnerHref());
} catch (final CalFacadeException cfe) {
errorReturn(resp, cfe);
return;
}
}
if (entity instanceof EventInfo) {
// This might be a single event or a recurring event.
final EventInfo ei = (EventInfo) entity;
final BwEvent ev = ei.getEvent();
if (ev.getRecurring()) {
resp.incRecurring();
}
if (!reindexEvent(hitResp, indexName, hit, ei, bulkProcessor)) {
warn("Unable to iondex event " + hit.sourceAsString());
resp.incTotalFailed();
if (resp.getTotalFailed() < 50) {
resp.addFailure(hitResp);
}
}
} else {
final EsDocInfo doc = makeDoc(resp, entity);
if (doc == null) {
if (resp.getStatus() != ok) {
resp.addFailure(hitResp);
}
continue;
}
final IndexRequest request = new IndexRequest(indexName, hit.type(), doc.getId());
request.source(doc.getSource());
bulkProcessor.add(request);
if (entity instanceof BwEventProperty) {
if (!cacheEvprop(hitResp, (BwEventProperty) entity)) {
resp.addFailure(hitResp);
}
}
}
}
scrollResp = cl.prepareSearchScroll(scrollResp.getScrollId()).setScroll(tv).execute().actionGet();
// Break condition: No hits are returned
if (scrollResp.getHits().getHits().length == 0) {
break;
}
}
try {
bulkProcessor.awaitClose(10, TimeUnit.MINUTES);
} catch (final InterruptedException e) {
errorReturn(resp, "Final bulk close was interrupted. Records may be missing", failed);
}
if (uidsSet > 0) {
info("Uids set: " + uidsSet);
info("uidOverridesSet: " + uidOverridesSet);
}
uidsMap = null;
uidsOverideMap = null;
}
use of org.bedework.calfacade.BwEventProperty in project bw-calendar-engine by Bedework.
the class CoreEventPropertiesDAO method delete.
public void delete(final BwEventProperty val) throws CalFacadeException {
final HibSession sess = getSess();
@SuppressWarnings("unchecked") final BwEventProperty v = (BwEventProperty) sess.merge(val);
sess.createQuery(delPrefsQuery.get(className));
sess.setInt("id", v.getId());
sess.executeUpdate();
sess.delete(v);
}
use of org.bedework.calfacade.BwEventProperty in project bw-calendar-engine by Bedework.
the class CoreEventPropertiesDAO method get.
@SuppressWarnings("unchecked")
public BwEventProperty get(final String uid) throws CalFacadeException {
if (getQuery == null) {
getQuery = "from " + className + " ent where uid=:uid";
}
final HibSession sess = getSess();
sess.createQuery(getQuery);
sess.setString("uid", uid);
return (BwEventProperty) sess.getUnique();
}
Aggregations