Search in sources :

Example 1 with N2oException

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;
}
Also used : N2oException(net.n2oapp.framework.api.exception.N2oException) CompiledObject(net.n2oapp.framework.api.metadata.local.CompiledObject) Domain(net.n2oapp.framework.api.metadata.domain.Domain)

Example 2 with N2oException

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 };
    }
}
Also used : N2oException(net.n2oapp.framework.api.exception.N2oException) N2oPathParam(net.n2oapp.framework.api.metadata.global.dao.N2oPathParam) N2oQueryParam(net.n2oapp.framework.api.metadata.global.dao.N2oQueryParam) N2oDatasource(net.n2oapp.framework.api.metadata.global.view.page.N2oDatasource) N2oPreFilter(net.n2oapp.framework.api.metadata.global.dao.N2oPreFilter)

Example 3 with N2oException

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);
        }
    }
}
Also used : N2oException(net.n2oapp.framework.api.exception.N2oException) MetadataRemovedEvent(net.n2oapp.framework.config.register.event.MetadataRemovedEvent) ConfigId(net.n2oapp.framework.config.register.ConfigId) RegisterUtil.createXmlInfo(net.n2oapp.framework.config.register.RegisterUtil.createXmlInfo) XmlInfo(net.n2oapp.framework.config.register.XmlInfo)

Example 4 with N2oException

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;
        }
    }
}
Also used : N2oException(net.n2oapp.framework.api.exception.N2oException) IOException(java.io.IOException)

Example 5 with N2oException

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"));
    }
}
Also used : N2oException(net.n2oapp.framework.api.exception.N2oException) PageContext(net.n2oapp.framework.config.metadata.compile.context.PageContext) HashSet(java.util.HashSet) Test(org.junit.Test)

Aggregations

N2oException (net.n2oapp.framework.api.exception.N2oException)60 DataSet (net.n2oapp.criteria.dataset.DataSet)13 IOException (java.io.IOException)10 PageScope (net.n2oapp.framework.config.metadata.compile.page.PageScope)6 Test (org.junit.Test)5 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)4 InputStream (java.io.InputStream)4 N2oQuery (net.n2oapp.framework.api.metadata.global.dao.N2oQuery)4 WidgetScope (net.n2oapp.framework.config.metadata.compile.widget.WidgetScope)4 ArrayList (java.util.ArrayList)3 HashMap (java.util.HashMap)3 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)3 MapInvocationEngine (net.n2oapp.framework.api.data.MapInvocationEngine)3 N2oUserException (net.n2oapp.framework.api.exception.N2oUserException)3 N2oClientDataProvider (net.n2oapp.framework.api.metadata.dataprovider.N2oClientDataProvider)3 CompiledObject (net.n2oapp.framework.api.metadata.local.CompiledObject)3 CompiledQuery (net.n2oapp.framework.api.metadata.local.CompiledQuery)3 PageContext (net.n2oapp.framework.config.metadata.compile.context.PageContext)3 BasicDBObject (com.mongodb.BasicDBObject)2 ConnectionString (com.mongodb.ConnectionString)2