* @param name
* @param link
* @return
*/
public static Echoarea getAreaByName(String name, Link link) {
Echoarea ret;
name = name.toLowerCase();
ret = ORMManager.get(Echoarea.class).getFirstAnd("name", "=", name);
if (ret == null) {
if (link == null
|| getOptionBooleanDefFalse(link,
LinkOption.BOOLEAN_AUTOCREATE_AREA)) {
ret = new Echoarea();
ret.setName(name);
ret.setDescription("Autocreated echoarea");
ret.setReadlevel((link != null) ? getOptionLong(link,
LinkOption.LONG_LINK_LEVEL) : 0);
ret.setWritelevel((link != null) ? getOptionLong(link,
LinkOption.LONG_LINK_LEVEL) : 0);
ret.setGroup((link != null) ? getOptionString(link,
LinkOption.SARRAY_LINK_GROUPS).split(" ")[0] : "");
logger.l3("Echoarea " + name.toUpperCase() + " created");
ORMManager.get(Echoarea.class).save(ret);
if (link != null) {
Subscription sub = new Subscription();
sub.setArea(ret);
sub.setLink(link);
ORMManager.get(Subscription.class).save(sub);
}
Notifier.INSTANSE.notify(new NewEchoareaEvent(name, link));
}
} else {
if (link != null
&& ORMManager.get(Subscription.class).getFirstAnd(
"echoarea_id", "=", ret.getId(), "link_id", "=",
link.getId()) == null) {
ret = null;
}
}
return ret;