use of org.bedework.calfacade.BwCategory in project bw-calendar-engine by Bedework.
the class DocBuilder method indexCategories.
private void indexCategories(final Collection<BwCategory> cats) throws CalFacadeException {
if (cats == null) {
return;
}
try {
startArray(getJname(PropertyInfoIndex.CATEGORIES));
for (final BwCategory cat : cats) {
startObject();
cat.fixNames(basicSysprops, principal);
makeField(PropertyInfoIndex.UID, cat.getUid());
makeField(PropertyInfoIndex.HREF, cat.getHref());
startArray(getJname(PropertyInfoIndex.VALUE));
// Eventually may be more of these
makeField((PropertyInfoIndex) null, cat.getWord());
endArray();
endObject();
}
endArray();
} catch (final IndexException e) {
throw new CalFacadeException(e);
}
}
use of org.bedework.calfacade.BwCategory in project bw-calendar-engine by Bedework.
the class EntityBuilder method makeCat.
BwCategory makeCat() throws CalFacadeException {
final BwCategory cat = new BwCategory();
restoreSharedEntity(cat);
cat.setName(getString(PropertyInfoIndex.NAME));
cat.setUid(getString(PropertyInfoIndex.UID));
cat.setWord((BwString) restoreBwString(PropertyInfoIndex.CATEGORIES, false));
cat.setDescription((BwString) restoreBwString(PropertyInfoIndex.DESCRIPTION, false));
return cat;
}
use of org.bedework.calfacade.BwCategory in project bw-calendar-engine by Bedework.
the class Filters method makeWhere.
/* Generate a where clause for a query which selects the events for the
* given filter.
*
* @param f Filter element.
*/
private void makeWhere(final FilterBase f) throws CalFacadeException {
if ((f instanceof AndFilter) || (f instanceof OrFilter)) {
boolean itsAnd = (f instanceof AndFilter);
qseg.append('(');
boolean first = true;
for (FilterBase flt : f.getChildren()) {
if (!first) {
if (itsAnd) {
qseg.append(" and ");
} else {
qseg.append(" or ");
}
}
makeWhere(flt);
first = false;
}
qseg.append(")");
}
if (f instanceof BwHrefFilter) {
// Special case this
qseg.append('(');
qseg.append(masterName);
qseg.append(".");
qseg.append("colPath");
qseg.append("=:");
parTerm();
qseg.append(" and ");
qseg.append(masterName);
qseg.append(".");
qseg.append("name");
qseg.append("=:");
parTerm();
qseg.append(')');
queryLimited = true;
} else if (f instanceof PropertyFilter) {
PropertyFilter pf = (PropertyFilter) f;
BwIcalPropertyInfoEntry pi = BwIcalPropertyInfo.getPinfo(pf.getPropertyIndex());
if (pi == null) {
throw new CalFacadeException("org.bedework.filters.unknownproperty", String.valueOf(pf.getPropertyIndex()));
}
String fieldName = pi.getDbFieldName();
boolean multi = pi.getMultiValued();
boolean param = pi.getParam();
if (param) {
BwIcalPropertyInfoEntry parentPi = BwIcalPropertyInfo.getPinfo(pf.getParentPropertyIndex());
fieldName = parentPi.getDbFieldName() + "." + fieldName;
}
if (multi) {
if (f instanceof PresenceFilter) {
PresenceFilter prf = (PresenceFilter) f;
// qseg.append("(size(");
qseg.append("((select count(*) from ");
qseg.append(masterName);
qseg.append(".");
qseg.append(fieldName);
if (pi.getPresenceField() != null) {
qseg.append(".");
qseg.append(pi.getPresenceField());
}
qseg.append(")");
if (prf.getTestPresent()) {
qseg.append(">0)");
} else {
qseg.append("=0)");
}
} else if (pf instanceof TimeRangeFilter) {
String fld = "joined_" + pi.getDbFieldName();
String subfld = "unknown";
if (pi.getPindex() == PropertyInfoIndex.VALARM) {
subfld = "triggerTime";
}
doTimeRange((TimeRangeFilter) pf, false, fld, subfld);
} else if (pf instanceof BwCategoryFilter) {
BwCategory cat = ((BwCategoryFilter) pf).getEntity();
if (cat.unsaved()) {
((BwCategoryFilter) pf).setEntity(cb.getCategory(cat.getUid()));
}
qseg.append("(:");
parTerm();
if (f.getNot()) {
qseg.append(" not");
}
qseg.append(" in elements(");
qseg.append(masterName);
qseg.append(".");
qseg.append(fieldName);
qseg.append("))");
} else if (pf instanceof BwObjectFilter) {
// String fld = "joined_" + pi.getField();
String subfld = "value";
// if (pi.getPindex() == PropertyInfoIndex.CATEGORIES) {
// subfld = "word.value";
// }
doObject(((BwObjectFilter) pf).getEntity(), masterName, fieldName, subfld, true);
} else {
qseg.append("(:");
parTerm();
if (f.getNot()) {
qseg.append(" not");
}
qseg.append(" in elements(");
qseg.append(masterName);
qseg.append(".");
qseg.append(fieldName);
qseg.append("))");
}
// not multi follow
} else if (f instanceof PresenceFilter) {
PresenceFilter prf = (PresenceFilter) f;
qseg.append('(');
qseg.append(masterName);
qseg.append(".");
qseg.append(fieldName);
if (prf.getTestPresent()) {
qseg.append(" is not null");
} else {
qseg.append(" is null");
}
qseg.append(")");
} else if (pf instanceof EntityTimeRangeFilter) {
doEntityTimeRange((EntityTimeRangeFilter) pf);
} else if (pf instanceof TimeRangeFilter) {
doTimeRange((TimeRangeFilter) pf, (pi.getFieldType().getName().equals(BwDateTime.class.getName())), masterName, fieldName);
} else if (pf instanceof BwObjectFilter) {
doObject(((BwObjectFilter) pf).getEntity(), masterName, fieldName, null, false);
} else {
/* We assume we can't handle this one as a query.
*/
throw new CalFacadeException("org.bedework.filters.unknownfilter", String.valueOf(f));
}
}
}
use of org.bedework.calfacade.BwCategory in project bw-calendar-engine by Bedework.
the class Dumper method dumpCategories.
protected void dumpCategories(final boolean publick) throws CalFacadeException {
try {
makeDir(Defs.categoriesDirName, false);
final Collection<BwCategory> cats;
if (publick) {
cats = getSvc().getCategoriesHandler().getPublic();
} else {
cats = getSvc().getCategoriesHandler().get();
}
for (final BwCategory cat : cats) {
incCount(DumpGlobals.categories);
final File catFile = makeFile(cat.getWordVal() + ".xml");
cat.dump(catFile);
}
} finally {
popPath();
}
}
use of org.bedework.calfacade.BwCategory in project bw-calendar-engine by Bedework.
the class BwStringRule method end.
@Override
public void end(final String ns, final String name) throws Exception {
if (name.equals("bwstring")) {
// 3.5 onwards we wrapped with a tag. Do nothing
return;
}
BwString entity = (BwString) pop();
if (top() instanceof BwRequestStatus) {
BwRequestStatus rs = (BwRequestStatus) top();
rs.setDescription(entity);
return;
}
if (top() instanceof BwCategory) {
BwCategory cat = (BwCategory) top();
if (name.equals("keyword")) {
cat.setWord(entity);
} else if (name.equals("desc")) {
cat.setDescription(entity);
} else {
unknownTag(name);
}
return;
}
if (top() instanceof BwContact) {
BwContact ent = (BwContact) top();
if (name.equals("value")) {
ent.setCn(entity);
} else {
unknownTag(name);
}
return;
}
if (top() instanceof BwLocation) {
BwLocation loc = (BwLocation) top();
if (name.equals("addr")) {
loc.setAddress(entity);
} else if (name.equals("subaddr")) {
loc.setSubaddress(entity);
} else {
unknownTag(name);
}
return;
}
if (top() instanceof BwFilterDef) {
BwFilterDef f = (BwFilterDef) top();
if (name.equals("display-name")) {
f.addDisplayName(entity);
} else if (name.equals("subaddr")) {
f.addDescription(new BwLongString(entity.getLang(), entity.getValue()));
} else {
unknownTag(name);
}
return;
}
if (top() instanceof BwAlarm) {
BwAlarm a = (BwAlarm) top();
if (name.equals("description")) {
a.addDescription(entity);
if (entity.getLang() != null) {
a.addXproperty(new BwXproperty(entity.getLang(), null, entity.getValue()));
} else {
a.addDescription(entity);
}
return;
}
if (name.equals("summary")) {
a.addSummary(entity);
} else {
unknownTag(name);
}
return;
}
EventInfo ei = (EventInfo) top();
BwEvent e = ei.getEvent();
if (e instanceof BwEventProxy) {
e = ((BwEventProxy) e).getRef();
}
if (name.equals("comment")) {
e.addComment(entity);
} else if (name.equals("description")) {
e.addDescription(new BwLongString(entity.getLang(), entity.getValue()));
} else if (name.equals("resource")) {
e.addResource(entity);
} else if (name.equals("summary")) {
e.addSummary(entity);
} else {
unknownTag(name);
}
}
Aggregations