* @param name
* @param link
* @return
*/
public static Filearea getFileareaByName(String name, Link link) {
Filearea ret;
name = name.toLowerCase();
ret = ORMManager.get(Filearea.class).getFirstAnd("name", "=", name);
if (ret == null) {
if (link == null
|| getOptionBooleanDefFalse(link,
LinkOption.BOOLEAN_AUTOCREATE_AREA)) {
ret = new Filearea();
ret.setName(name);
ret.setDescription("Autocreated filearea");
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("Filearea " + name + " created");
ORMManager.get(Filearea.class).save(ret);
if (link != null) {
FileSubscription sub = new FileSubscription();
sub.setArea(ret);
sub.setLink(link);
ORMManager.get(FileSubscription.class).save(sub);
}
Notifier.INSTANSE.notify(new NewFileareaEvent(name, link));
}
} else {
if (link != null
&& ORMManager.get(FileSubscription.class).getFirstAnd(
"filearea_id", "=", ret.getId(), "link_id", "=",
link.getId()) == null) {
ret = null;
}
}
return ret;