}
if (condition.getStartDate() == null) {
throw new IllegalArgumentException("StartDate is null.");
}
Calendar calendar = new Calendar();
calendar.getProperties().add(PROD_ID);
calendar.getProperties().add(Version.VERSION_2_0);
calendar.getProperties().add(new XProperty("X-WR-CALNAME", CALNAME));
NicoliveMeta n = NicoliveMeta.get();
NicoliveIndexMeta ni = NicoliveIndexMeta.get();
ModelQuery<Nicolive> query =
Datastore
.query(n)
.filter(
n.openTime.greaterThanOrEqual(condition.getStartDate()))
.sort(n.openTime.getName(), SortDirection.ASCENDING);
if (condition.getKeywords() != null
&& 0 < condition.getKeywords().size()) {
List<Key> keywordKeys = new LinkedList<Key>();
for (String keyword : condition.getKeywords()) {
List<NicoliveIndex> indexes =
Datastore
.query(ni)
.filter(ni.keyword.equal(keyword))
.asList();
List<Key> keys = new LinkedList<Key>();
for (NicoliveIndex nicoliveIndex : indexes) {
keys.add(nicoliveIndex.getNicoliveKey());
}
keywordKeys = merge(keys, keywordKeys);
}
if (0 < keywordKeys.size()) {
query = query.filterInMemory(n.key.in(keywordKeys));
} else {
// キーワード検索で該当するエンティティがなければ、この後のクエリを発行する必要がないので、ここで検索を終了とする。
return calendar;
}
}
TimeZone timezone = TimeZoneLocator.get();
List<Nicolive> nicolives = query.asList();
for (Nicolive nicolive : nicolives) {
PropertyList properties = new PropertyList();
properties.add(new Summary(nicolive.getTitle()));
String description;
try {
description =
HtmlRemoveUtil.removeHtml(nicolive
.getDescription()
.getValue());
} catch (SAXException e1) {
description = "";
} catch (IOException e1) {
description = "";
}
java.util.Calendar c = DateUtil.toCalendar(nicolive.getOpenTime());
c.setTimeZone(timezone);
properties.add(new Description(description));
properties.add(new DtStart(new DateTime(c.getTime()), true));
properties.add(new DtEnd(new DateTime(c.getTime()), true));
try {
URI uri = new URI(nicolive.getLink().getValue());
properties.add(new Url(uri));
} catch (URISyntaxException e) {
LOGGER.warning(e.getMessage());
}
VEvent event = new VEvent(properties);
calendar.getComponents().add(event);
}
return calendar;
}