use of net.n2oapp.framework.api.exception.N2oException in project n2o-framework by i-novus-llc.
the class DomainProcessor method findDomain.
private String findDomain(Object value) {
if (value instanceof Collection) {
if (((Collection) value).isEmpty())
// не важно какой тип элементов списка, если он пустой
return "integer[]";
Object firstElement = ((Collection) value).iterator().next();
String elementsDomain = (findDomain(firstElement));
if (elementsDomain == null)
return null;
return elementsDomain + "[]";
}
if (value instanceof String) {
String val = ((String) value).toLowerCase();
if (val.equals("true") || value.equals("false"))
return Domain.BOOLEAN.getName();
if (val.length() <= 6 && val.chars().allMatch(Character::isDigit)) {
try {
Integer.parseInt(val);
} catch (NumberFormatException e) {
throw new N2oException("Value is not Integer [" + val + "]. Set domain explicitly!", e);
}
return Domain.INTEGER.getName();
}
return Domain.STRING.getName();
}
// подбираем домен по классу значения
Domain domain = Domain.getByClass(value.getClass());
return domain != null ? domain.getName() : null;
}
use of net.n2oapp.framework.api.exception.N2oException in project n2o-framework by i-novus-llc.
the class N2oAbstractPageAction method adaptV1.
@Deprecated
public void adaptV1() {
if (getUpload() != null || getDetailFieldId() != null || getPreFilters() != null) {
N2oDatasource datasource = new N2oDatasource();
if (getUpload() != null) {
switch(getUpload()) {
case query:
datasource.setDefaultValuesMode(DefaultValuesMode.query);
break;
case defaults:
datasource.setDefaultValuesMode(DefaultValuesMode.defaults);
break;
case copy:
datasource.setDefaultValuesMode(DefaultValuesMode.merge);
break;
}
}
if (getDetailFieldId() != null && !UploadType.defaults.equals(getUpload())) {
N2oPreFilter filter = new N2oPreFilter();
filter.setFieldId(getDetailFieldId());
filter.setType(FilterType.eq);
filter.setValueAttr(Placeholders.ref(getMasterFieldId() != null ? getMasterFieldId() : PK));
String param = getMasterParam();
if (param == null && getRoute() != null && getRoute().contains(":")) {
if (getRoute().indexOf(":") != getRoute().lastIndexOf(":"))
throw new N2oException(String.format("Невозможно определить параметр для detail-field-id в пути %s, необходимо задать master-param", getRoute()));
param = getRoute().substring(getRoute().indexOf(":") + 1, getRoute().lastIndexOf("/"));
}
if (param == null) {
param = "$widgetId_" + getDetailFieldId();
}
if (getRoute() != null && getRoute().contains(":" + param)) {
N2oPathParam pathParam = new N2oPathParam();
pathParam.setName(param);
pathParam.setDatasource(filter.getDatasource());
pathParam.setModel(filter.getModel());
pathParam.setValue(filter.getValueAttr());
boolean exists = false;
if (getPathParams() != null) {
for (N2oPathParam oldPathParam : getPathParams()) {
if (oldPathParam.getName().equals(param)) {
exists = true;
break;
}
}
}
if (!exists)
addPathParams(new N2oPathParam[] { pathParam });
} else if (!ReduxModel.filter.equals(filter.getModel())) {
N2oQueryParam queryParam = new N2oQueryParam();
queryParam.setName(param);
queryParam.setDatasource(filter.getDatasource());
queryParam.setModel(filter.getModel());
queryParam.setValue(filter.getValueAttr());
boolean exists = false;
if (getQueryParams() != null) {
for (N2oQueryParam oldQueryParam : getQueryParams()) {
if (oldQueryParam.getName().equals(param)) {
exists = true;
break;
}
}
}
if (!exists)
addQueryParams(new N2oQueryParam[] { queryParam });
}
filter.setParam(param);
datasource.addFilters(List.of(filter));
}
if (preFilters != null) {
datasource.addFilters(Arrays.asList(preFilters));
}
datasources = new N2oDatasource[] { datasource };
}
}
use of net.n2oapp.framework.api.exception.N2oException in project n2o-framework by i-novus-llc.
the class MetadataPersister method remove.
public void remove(String id, Class<? extends N2oMetadata> metadataClass) {
checkLock();
XmlInfo info = (XmlInfo) metadataRegister.get(id, metadataClass);
if (info != null && info.getURI() != null) {
String path = PathUtil.convertUrlToAbsolutePath(info.getURI());
if (path == null)
throw new IllegalStateException();
watchDir.skipOn(info.getURI());
try {
if (removeContentByUri(info.getURI())) {
ConfigId configId = info.getConfigId();
metadataRegister.remove(configId.getId(), configId.getBaseSourceClass());
eventBus.publish(new MetadataRemovedEvent(this, info));
} else {
throw new N2oException("n2o.couldNotDeleteFile").addData(info.getLocalPath());
}
} finally {
watchDir.takeOn(path);
}
}
}
use of net.n2oapp.framework.api.exception.N2oException in project n2o-framework by i-novus-llc.
the class InfoStatus method calculateStatusByFile.
public static Status calculateStatusByFile(XmlInfo info, boolean checkDiff, boolean checkDuplicate) {
boolean isServerFile = isServerFile(info);
boolean hasAncestor = info.getAncestor() != null;
if (hasAncestor) {
if (checkDuplicate) {
boolean hasDuplicateAncestor = findNotEqualsLocalPath(info.getAncestor(), info.getLocalPath()) != null;
if (hasDuplicateAncestor)
return Status.DUPLICATE;
}
try {
if (info.getLocalPath().equals(info.getAncestor().getLocalPath()) && info.getUri().equals(info.getAncestor().getUri())) {
return Status.SERVER;
}
boolean isIdenticalContent = isIdenticalContentSimple(info.getAncestor().getURI(), info.getURI(), checkDiff);
if (isIdenticalContent) {
return Status.SYSTEM;
} else {
return Status.MODIFY;
}
} catch (IOException e) {
throw new N2oException(e);
}
} else {
if (isServerFile) {
return Status.SERVER;
} else {
return Status.SYSTEM;
}
}
}
use of net.n2oapp.framework.api.exception.N2oException in project n2o-framework by i-novus-llc.
the class TabsRegionCompileTest method testTabIdUnique.
@Test
public void testTabIdUnique() {
// неуникальные id на одной странице
try {
compile("net/n2oapp/framework/config/metadata/compile/region/testTabsRegionUniqueId.page.xml").get(new PageContext("testTabsRegionUniqueId"));
assertFalse(true);
} catch (N2oException e) {
assertThat(e.getMessage(), is("test tab is already exist"));
}
// неуникальные id на родительской и открываемой странице
try {
PageContext pageContext = new PageContext("testTabsRegionUniqueId2");
HashSet<String> tabIds = new HashSet<>();
tabIds.add("test");
pageContext.setParentTabIds(tabIds);
compile("net/n2oapp/framework/config/metadata/compile/region/testTabsRegionUniqueId2.page.xml").get(pageContext);
assertFalse(true);
} catch (N2oException e) {
assertThat(e.getMessage(), is("test tab is already exist"));
}
}
Aggregations