use of org.bedework.calfacade.BwCategory in project bw-calendar-engine by Bedework.
the class Filters method parReplace.
/* Fill in the parameters after we generated the query.
*/
private void parReplace(final FilterBase f) throws CalFacadeException {
if (f instanceof AndFilter) {
AndFilter fb = (AndFilter) f;
for (FilterBase flt : fb.getChildren()) {
parReplace(flt);
}
return;
}
if (f instanceof BwHrefFilter) {
BwHrefFilter hf = (BwHrefFilter) f;
// Special case this
sess.setString(parPrefix + qi, hf.getPathPart());
qi++;
sess.setString(parPrefix + qi, hf.getNamePart());
qi++;
}
if (f instanceof BwCategoryFilter) {
BwCategoryFilter cf = (BwCategoryFilter) f;
BwCategory cat = cf.getEntity();
/* XXX - this is what we want to be able to do
sess.setString(parPrefix + qi, cat.getUid());
*/
sess.setEntity(parPrefix + qi, cat);
qi++;
return;
}
if (f instanceof EntityTimeRangeFilter) {
doEntityTimeRangeReplace((EntityTimeRangeFilter) f);
return;
}
if (f instanceof TimeRangeFilter) {
TimeRangeFilter trf = (TimeRangeFilter) f;
TimeRange tr = trf.getEntity();
if (tr.getStart() != null) {
sess.setParameter(parPrefix + qi, tr.getStart().toString());
qi++;
}
if (tr.getEnd() != null) {
sess.setParameter(parPrefix + qi, tr.getEnd().toString());
qi++;
}
return;
}
if (f instanceof BwObjectFilter) {
ObjectFilter of = ((BwObjectFilter) f).getEntity();
Object o = of.getEntity();
Collection c = null;
boolean isString = o instanceof String;
if (!isString) {
if (o instanceof Collection) {
c = (Collection) o;
if (c.size() > 0) {
o = c.iterator().next();
isString = o instanceof String;
}
}
}
boolean doCaseless = isString && of.getCaseless();
if (c != null) {
// TODO - Assuming String collection
for (Object co : c) {
String s = (String) co;
if (doCaseless) {
s = s.toLowerCase();
}
sess.setParameter(parPrefix + qi, s);
qi++;
}
return;
}
if (o instanceof BwCalendar) {
BwCalendar cal = unwrap((BwCalendar) o);
sess.setString(parPrefix + qi, cal.getPath());
} else if (o instanceof BwPrincipal) {
sess.setString(parPrefix + qi, ((BwPrincipal) o).getPrincipalRef());
} else if (o instanceof BwDbentity) {
sess.setEntity(parPrefix + qi, o);
} else if (of.getExact()) {
if (doCaseless) {
o = ((String) o).toLowerCase();
}
sess.setParameter(parPrefix + qi, o);
} else if (of.getEntity() instanceof String) {
String s = o.toString();
if (doCaseless) {
s = s.toLowerCase();
}
sess.setString(parPrefix + qi, "%" + s + "%");
} else {
sess.setString(parPrefix + qi, "%" + o + "%");
}
qi++;
return;
}
if (f instanceof OrFilter) {
OrFilter fb = (OrFilter) f;
for (FilterBase flt : fb.getChildren()) {
parReplace(flt);
}
return;
}
}
use of org.bedework.calfacade.BwCategory in project bw-calendar-engine by Bedework.
the class PrincipalsAndPrefsDAO method removeFromAllPrefs.
public void removeFromAllPrefs(final BwShareableDbentity val) throws CalFacadeException {
final HibSession sess = getSess();
final String q;
if (val instanceof BwCategory) {
q = getCategoryPrefForAllQuery;
} else if (val instanceof BwCalendar) {
q = removeCalendarPrefForAllQuery;
} else if (val instanceof BwContact) {
q = removeContactPrefForAllQuery;
} else if (val instanceof BwLocation) {
q = removeLocationPrefForAllQuery;
} else {
throw new CalFacadeException("Can't handle " + val);
}
sess.createQuery(q);
sess.setInt("id", val.getId());
sess.executeUpdate();
}
use of org.bedework.calfacade.BwCategory in project bw-calendar-engine by Bedework.
the class Restorer method restoreCategories.
protected void restoreCategories() throws CalFacadeException {
try {
final Path p = openDir(Defs.categoriesDirName);
if (p == null) {
return;
}
final DirRestore<BwCategory> dirRestore = new DirRestore<>(p, restoreCat);
final EnumSet<FileVisitOption> opts = EnumSet.of(FileVisitOption.FOLLOW_LINKS);
Files.walkFileTree(p, opts, Integer.MAX_VALUE, dirRestore);
} catch (final IOException ie) {
throw new CalFacadeException(ie);
} finally {
popPath();
}
}
use of org.bedework.calfacade.BwCategory in project bw-calendar-engine by Bedework.
the class AuthUserFieldRule method field.
/* (non-Javadoc)
* @see org.bedework.dumprestore.restore.rules.EntityFieldRule#field(java.lang.String)
*/
@Override
public void field(final String name) throws Throwable {
BwEventProperty ep = null;
BwCalendar cal = null;
try {
if (top() instanceof BwEventProperty) {
ep = (BwEventProperty) pop();
} else if (top() instanceof BwCalendar) {
cal = (BwCalendar) pop();
}
BwAuthUser au = (BwAuthUser) top();
if (name.equals("id") || name.equals("seq")) {
return;
}
if (name.equals("userHref")) {
au.setUserHref(Util.buildPath(false, stringFld()));
// } else if (name.equals("account")) { old?
// au.setUserHref(globals.rintf.getUser(stringFld()).getPrincipalRef());
// } else if (name.equals("user")) {
// // done above
} else if (name.equals("usertype")) {
int type = intFld();
au.setUsertype(type);
/* Prefs stuff next */
} else if (name.equals("autoAdd")) {
if (inCategoryPrefs) {
getCategoryPrefs(au).setAutoAdd(booleanFld());
} else if (inCollectionsPrefs) {
getCalendarPrefs(au).setAutoAdd(booleanFld());
} else if (inContactPrefs) {
getContactPrefs(au).setAutoAdd(booleanFld());
} else if (inLocationPrefs) {
getLocationPrefs(au).setAutoAdd(booleanFld());
} else {
error("Not in any prefs for autoAdd");
}
} else if (name.equals("category")) {
au.getPrefs().getCategoryPrefs().add((BwCategory) ep);
} else if (name.equals("collection")) {
au.getPrefs().getCalendarPrefs().add(cal);
} else if (name.equals("contact")) {
au.getPrefs().getContactPrefs().add((BwContact) ep);
} else if (name.equals("location")) {
au.getPrefs().getLocationPrefs().add((BwLocation) ep);
} else if (name.equals("categoryPrefs")) {
inCategoryPrefs = false;
} else if (name.equals("calendarPrefs")) {
inCollectionsPrefs = false;
} else if (name.equals("contactPrefs")) {
inContactPrefs = false;
} else if (name.equals("locationPrefs")) {
inLocationPrefs = false;
} else if (name.equals("prefs")) {
} else if (name.equals("byteSize")) {
} else {
unknownTag(name);
}
} catch (Throwable t) {
handleException(t);
}
}
use of org.bedework.calfacade.BwCategory in project bw-calendar-engine by Bedework.
the class CategoryFieldRule method field.
public void field(String name) throws Exception {
BwString s = null;
if (top() instanceof BwString) {
s = (BwString) pop();
}
BwCategory cat = (BwCategory) top();
if (shareableEntityTags(cat, name)) {
return;
}
if (name.equals("word")) {
cat.setWord(s);
} else if (name.equals("description")) {
cat.setDescription(s);
} else if (name.equals("uid")) {
cat.setUid(stringFld());
} else if (name.equals("byteSize")) {
cat.setByteSize(intFld());
} else {
unknownTag(name);
}
}
Aggregations