Search in sources :

Example 6 with Record

use of jp.ossc.nimbus.beans.dataset.Record in project nimbus by nimbus-org.

the class DataSetXpathConverter method createRecord.

private void createRecord(Document document, DataSet dataSet, Object target, RecordSchema recordSchema) {
    PropertySchema[] propertySchemata = recordSchema.getPropertySchemata();
    for (int i = 0; i < propertySchemata.length; i++) {
        if (propertySchemata[i] instanceof XpathPropertySchema) {
            // PropertySchemaからXPath取得
            XpathPropertySchema xmlBindingPropertySchema = (XpathPropertySchema) propertySchemata[i];
            XPathExpression expression = xmlBindingPropertySchema.getXpathExpression();
            // XPathによりXML要素を抽出
            NodeList nodeList = null;
            try {
                nodeList = (NodeList) expression.evaluate(document, XPathConstants.NODESET);
            } catch (XPathExpressionException e) {
                throw new ConvertException("The converter failed to evaluate a XML. ", e);
            }
            // DataSetへ変換
            int length = nodeList.getLength();
            if (target instanceof Record) {
                if (length > 0) {
                    Object nodeValue = nodeList.item(0).getNodeValue();
                    ((Record) target).setParseProperty(xmlBindingPropertySchema.getName(), nodeValue);
                }
            } else if (target instanceof RecordList) {
                RecordList targetRecordList = (RecordList) target;
                int offset = length - targetRecordList.size();
                if (offset > 0) {
                    for (int j = 0; j < offset; j++) {
                        Record record = targetRecordList.createRecord();
                        targetRecordList.addRecord(record);
                    }
                }
                for (int j = 0; j < length; j++) {
                    Object nodeValue = nodeList.item(j).getNodeValue();
                    Record record = targetRecordList.getRecord(j);
                    record.setParseProperty(xmlBindingPropertySchema.getName(), nodeValue);
                }
            }
        } else if (propertySchemata[i] instanceof RecordPropertySchema) {
            RecordPropertySchema recordPropertySchema = (RecordPropertySchema) propertySchemata[i];
            RecordSchema nestedRecordSchema = dataSet.getNestedRecordSchema(recordPropertySchema.getName());
            Record nestedRecord = dataSet.createNestedRecord(recordPropertySchema.getRecordName());
            createRecord(document, dataSet, target, nestedRecordSchema);
            ((Record) target).setProperty(recordPropertySchema.getName(), nestedRecord);
        } else if (propertySchemata[i] instanceof RecordListPropertySchema) {
            RecordListPropertySchema recordListPropertySchema = (RecordListPropertySchema) propertySchemata[i];
            RecordSchema nestedRecordSchema = dataSet.getNestedRecordListSchema(recordListPropertySchema.getRecordListName());
            RecordList nestedRecordList = dataSet.createNestedRecordList(recordListPropertySchema.getRecordListName());
            createRecord(document, dataSet, nestedRecordList, nestedRecordSchema);
            ((Record) target).setProperty(recordListPropertySchema.getName(), nestedRecordList);
        }
    }
}
Also used : XPathExpression(javax.xml.xpath.XPathExpression) XpathPropertySchema(jp.ossc.nimbus.beans.dataset.XpathPropertySchema) PropertySchema(jp.ossc.nimbus.beans.dataset.PropertySchema) RecordPropertySchema(jp.ossc.nimbus.beans.dataset.RecordPropertySchema) RecordListPropertySchema(jp.ossc.nimbus.beans.dataset.RecordListPropertySchema) XPathExpressionException(javax.xml.xpath.XPathExpressionException) NodeList(org.w3c.dom.NodeList) RecordList(jp.ossc.nimbus.beans.dataset.RecordList) Record(jp.ossc.nimbus.beans.dataset.Record) RecordPropertySchema(jp.ossc.nimbus.beans.dataset.RecordPropertySchema) RecordSchema(jp.ossc.nimbus.beans.dataset.RecordSchema) RecordListPropertySchema(jp.ossc.nimbus.beans.dataset.RecordListPropertySchema) XpathPropertySchema(jp.ossc.nimbus.beans.dataset.XpathPropertySchema)

Example 7 with Record

use of jp.ossc.nimbus.beans.dataset.Record in project nimbus by nimbus-org.

the class BlockadeInterceptorService method invokeFilter.

/**
 * コードマスタの閉塞マスタ及び特権ユーザマスタをチェックして、閉塞状態の場合は例外をthrowする。
 * <p>
 * サービスが開始されていない場合は、何もせずに次のインターセプタを呼び出す。<br>
 *
 * @param context 呼び出しのコンテキスト情報
 * @param chain 次のインターセプタを呼び出すためのチェーン
 * @return 呼び出し結果の戻り値
 * @exception Throwable 呼び出し先で例外が発生した場合、またはこのインターセプタで任意の例外が発生した場合。但し、
 *                本来呼び出される処理がthrowしないRuntimeException以外の例外をthrowしても
 *                、呼び出し元には伝播されない。
 */
public Object invokeFilter(ServletFilterInvocationContext context, InterceptorChain chain) throws Throwable {
    if (getState() != STARTED) {
        return chain.invokeNext(context);
    }
    final HttpServletRequest request = (HttpServletRequest) context.getServletRequest();
    String reqPath = request.getServletPath();
    if (request.getPathInfo() != null) {
        reqPath = reqPath + request.getPathInfo();
    }
    Map codeMasters = null;
    if (codeMasterFinder != null) {
        codeMasters = codeMasterFinder.getCodeMasters();
    } else {
        codeMasters = (Map) threadContext.get(ThreadContextKey.CODEMASTER);
    }
    if (codeMasters == null) {
        throw new BlockadeProcessException("CodeMaster is null.");
    }
    Object blockadeCodeMaster = codeMasters.get(blockadeCodeMasterKey);
    if (blockadeCodeMaster == null) {
        throw new BlockadeProcessException("BlockadeCodeMaster is null. key=" + blockadeCodeMasterKey);
    }
    Object specialUserCodeMaster = null;
    if (specialUserCodeMasterKey != null) {
        specialUserCodeMaster = codeMasters.get(specialUserCodeMasterKey);
    }
    boolean isSpecialUser = false;
    String userKey = null;
    if (specialUserCodeMaster != null) {
        Object requestObject = request.getAttribute(requestObjectAttributeName);
        if (requestObject == null) {
            throw new BlockadeProcessException("RequestObject is null.");
        }
        if (specialUserCodeMaster instanceof RecordList) {
            RecordList list = (RecordList) specialUserCodeMaster;
            Record primaryKey = list.createRecord();
            applySpecialUserMapping(requestObject, primaryKey);
            userKey = primaryKey.toString();
            isSpecialUser = list.searchByPrimaryKey(primaryKey) != null;
        } else if (specialUserCodeMaster instanceof RecordSet) {
            RecordSet recset = (RecordSet) specialUserCodeMaster;
            RowData primaryKey = recset.createNewRecord();
            applySpecialUserMapping(requestObject, primaryKey);
            userKey = primaryKey.getKey();
            isSpecialUser = recset.get(primaryKey) != null;
        } else {
            throw new BlockadeProcessException("Unsupported type of SpecialUserCodeMaster. type=" + specialUserCodeMaster.getClass());
        }
    }
    if (pathPatternMap == null) {
        initPathPatternMap(blockadeCodeMaster);
    }
    Map blockadeFilterMap = null;
    if (blockadeMapping != null) {
        Object requestObject = request.getAttribute(requestObjectAttributeName);
        if (requestObject == null) {
            throw new BlockadeProcessException("RequestObject is null.");
        }
        blockadeFilterMap = new HashMap();
        Iterator entries = blockadeMapping.entrySet().iterator();
        while (entries.hasNext()) {
            Map.Entry entry = (Map.Entry) entries.next();
            try {
                blockadeFilterMap.put(entry.getValue(), propertyAccess.get(requestObject, (String) entry.getKey()));
            } catch (IllegalArgumentException e) {
                throw new BlockadeProcessException("BlockadeCodeMaster value '" + entry.getKey() + "' cannot acquire from a request.", e);
            } catch (NoSuchPropertyException e) {
                throw new BlockadeProcessException("BlockadeCodeMaster value '" + entry.getKey() + "' cannot acquire from a request.", e);
            } catch (InvocationTargetException e) {
                throw new BlockadeProcessException("BlockadeCodeMaster value '" + entry.getKey() + "' cannot acquire from a request.", e.getTargetException());
            }
        }
    }
    if (blockadeCodeMaster instanceof List) {
        List list = (List) blockadeCodeMaster;
        for (int i = 0, imax = list.size(); i < imax; i++) {
            Object blockade = list.get(i);
            if (blockadeFilterMap != null) {
                if (!isMatchBlockadeMapping(blockadeFilterMap, blockade)) {
                    continue;
                }
            }
            checkBlockade(reqPath, blockade, isSpecialUser, userKey);
        }
    } else if (blockadeCodeMaster instanceof RecordSet) {
        RecordSet recset = (RecordSet) blockadeCodeMaster;
        for (int i = 0, imax = recset.size(); i < imax; i++) {
            Object blockade = recset.get(i);
            if (blockadeFilterMap != null) {
                if (!isMatchBlockadeMapping(blockadeFilterMap, blockade)) {
                    continue;
                }
            }
            checkBlockade(reqPath, blockade, isSpecialUser, userKey);
        }
    } else {
        throw new BlockadeProcessException("Unsupported type of BlockadeCodeMaster. type=" + blockadeCodeMaster.getClass());
    }
    return chain.invokeNext(context);
}
Also used : HashMap(java.util.HashMap) InvocationTargetException(java.lang.reflect.InvocationTargetException) RowData(jp.ossc.nimbus.recset.RowData) RecordList(jp.ossc.nimbus.beans.dataset.RecordList) Iterator(java.util.Iterator) NoSuchPropertyException(jp.ossc.nimbus.beans.NoSuchPropertyException) Record(jp.ossc.nimbus.beans.dataset.Record) RecordList(jp.ossc.nimbus.beans.dataset.RecordList) List(java.util.List) RecordSet(jp.ossc.nimbus.recset.RecordSet) HashMap(java.util.HashMap) Map(java.util.Map)

Example 8 with Record

use of jp.ossc.nimbus.beans.dataset.Record in project nimbus by nimbus-org.

the class RecordListJournalEditorService method makeRecordsFormat.

protected StringBuilder makeRecordsFormat(EditorFinder finder, Object key, RecordList list, StringBuilder buf) {
    buf.append(RECORDS_HEADER);
    final int size = list.size();
    if (size == 0) {
        buf.append(NULL_STRING);
        return buf;
    } else {
        buf.append(getLineSeparator());
    }
    final StringBuilder subBuf = new StringBuilder();
    for (int i = 0, max = (maxSize > 0 && maxSize < size) ? maxSize : size; i <= max; i++) {
        if (i != max) {
            Record record = (Record) list.get(i);
            makeObjectFormat(finder, null, record, subBuf);
            subBuf.append(getLineSeparator());
        } else if (list.size() > max) {
            subBuf.append(MAX_SIZE_OVER);
        }
    }
    addIndent(subBuf);
    return buf.append(subBuf);
}
Also used : Record(jp.ossc.nimbus.beans.dataset.Record)

Example 9 with Record

use of jp.ossc.nimbus.beans.dataset.Record in project nimbus by nimbus-org.

the class RecordJournalEditorService method processBlock.

protected boolean processBlock(EditorFinder finder, Object key, Object value, StringBuilder buf) {
    final Record bean = (Record) value;
    boolean isMake = false;
    if (isOutputRecordSchema()) {
        makeRecordSchemaFormat(finder, key, bean, buf);
        isMake = true;
    }
    if (isOutputProperties()) {
        if (isMake) {
            buf.append(getLineSeparator());
        }
        makePropertiesFormat(finder, key, bean, buf);
        isMake = true;
    }
    return isMake;
}
Also used : Record(jp.ossc.nimbus.beans.dataset.Record)

Example 10 with Record

use of jp.ossc.nimbus.beans.dataset.Record in project nimbus by nimbus-org.

the class MasterValidatorService method validate.

/**
 * 指定されたオブジェクトがマスタに含まれているかを検証する。<p>
 *
 * @param obj 検証対象のオブジェクト
 * @return 検証結果。検証成功の場合true
 * @exception ValidateException 検証に失敗した場合
 */
public boolean validate(Object obj) throws ValidateException {
    if (connectionFactory != null) {
        if (persistentManager != null) {
            Connection con = null;
            try {
                con = connectionFactory.getConnection();
                final List result = (List) persistentManager.loadQuery(con, query, obj, null);
                if (result.size() == 0) {
                    return false;
                }
                final Collection values = ((Map) result.get(0)).values();
                if (values.size() == 0) {
                    return false;
                }
                if (values.size() == 1) {
                    final Object value = values.iterator().next();
                    if (value instanceof Boolean) {
                        return ((Boolean) value).booleanValue();
                    } else if (value instanceof Number) {
                        return ((Number) value).intValue() != 0;
                    } else {
                        return true;
                    }
                } else {
                    return true;
                }
            } catch (ConnectionFactoryException e) {
                throw new ValidateException(e);
            } catch (PersistentException e) {
                throw new ValidateException(e);
            } finally {
                if (con != null) {
                    try {
                        con.close();
                    } catch (SQLException e) {
                    }
                }
            }
        } else {
            final RecordSet recset = templateRecordSet.cloneEmpty();
            Connection con = null;
            try {
                con = connectionFactory.getConnection();
                recset.setConnection(con);
                recset.setLogger(getLogger());
                for (int i = 0, imax = bindDataList.size(); i < imax; i++) {
                    final Property prop = (Property) bindDataList.get(i);
                    if (prop == null) {
                        recset.setBindData(i, obj);
                    } else {
                        recset.setBindData(i, prop.getProperty(obj));
                    }
                }
                return recset.search() != 0;
            } catch (ConnectionFactoryException e) {
                throw new ValidateException(e);
            } catch (NoSuchPropertyException e) {
                throw new ValidateException(e);
            } catch (InvocationTargetException e) {
                throw new ValidateException(e.getCause());
            } catch (SQLException e) {
                throw new ValidateException(e);
            } finally {
                if (con != null) {
                    try {
                        con.close();
                    } catch (SQLException e) {
                    }
                }
            }
        }
    } else {
        Map codeMaster = null;
        if (threadContext != null) {
            codeMaster = (Map) threadContext.get(codeMasterThreadContextKey);
        }
        if (codeMaster == null && codeMasterFinder != null) {
            codeMaster = codeMasterFinder.getCodeMasters();
        }
        if (codeMaster == null) {
            throw new ValidateException("CodeMaster is not found.");
        }
        final Object master = codeMaster.get(codeMasterName);
        if (master == null) {
            throw new ValidateException("Master '" + codeMasterName + "' is not found.");
        }
        if (master instanceof RecordSet) {
            final RecordSet recset = (RecordSet) master;
            if (searchCondition != null) {
                final Map params = new HashMap();
                final Iterator entries = bindDataMap.entrySet().iterator();
                try {
                    while (entries.hasNext()) {
                        final Map.Entry entry = (Map.Entry) entries.next();
                        final String key = (String) entry.getKey();
                        final Property prop = (Property) entry.getValue();
                        if (prop == null) {
                            params.put(key, obj);
                        } else {
                            params.put(key, prop.getProperty(obj));
                        }
                    }
                } catch (NoSuchPropertyException e) {
                    throw new ValidateException(e);
                } catch (InvocationTargetException e) {
                    throw new ValidateException(e.getCause());
                }
                try {
                    return recset.searchDynamicConditionReal(searchCondition, params).size() != 0;
                } catch (Exception e) {
                    throw new ValidateException(e);
                }
            } else {
                return recset.get(obj == null ? null : obj.toString()) != null;
            }
        } else if (master instanceof RecordList) {
            final RecordList recordList = (RecordList) master;
            if (searchCondition != null) {
                final Map params = new HashMap();
                final Iterator entries = bindDataMap.entrySet().iterator();
                try {
                    while (entries.hasNext()) {
                        final Map.Entry entry = (Map.Entry) entries.next();
                        final String key = (String) entry.getKey();
                        final Property prop = (Property) entry.getValue();
                        if (prop == null) {
                            params.put(key, obj);
                        } else {
                            params.put(key, prop.getProperty(obj));
                        }
                    }
                } catch (NoSuchPropertyException e) {
                    throw new ValidateException(e);
                } catch (InvocationTargetException e) {
                    throw new ValidateException(e.getCause());
                }
                try {
                    return recordList.realSearch(searchCondition, params).size() != 0;
                } catch (Exception e) {
                    throw new ValidateException(e);
                }
            } else {
                PropertySchema[] schemata = recordList.getRecordSchema().getPrimaryKeyPropertySchemata();
                if (schemata == null || schemata.length != 1) {
                    throw new ValidateException("Size of primary key property not equal 1.");
                }
                Record key = recordList.createRecord();
                key.setProperty(schemata[0].getName(), obj);
                return recordList.searchByPrimaryKey(key) != null;
            }
        } else {
            throw new ValidateException("Master '" + codeMasterName + "' is not supported type. type=" + master.getClass().getName());
        }
    }
}
Also used : ValidateException(jp.ossc.nimbus.util.validator.ValidateException) PersistentException(jp.ossc.nimbus.service.connection.PersistentException) ConnectionFactoryException(jp.ossc.nimbus.service.connection.ConnectionFactoryException) InvocationTargetException(java.lang.reflect.InvocationTargetException) PersistentException(jp.ossc.nimbus.service.connection.PersistentException) InvocationTargetException(java.lang.reflect.InvocationTargetException) ConnectionFactoryException(jp.ossc.nimbus.service.connection.ConnectionFactoryException) ValidateException(jp.ossc.nimbus.util.validator.ValidateException) RecordList(jp.ossc.nimbus.beans.dataset.RecordList) RecordList(jp.ossc.nimbus.beans.dataset.RecordList) Record(jp.ossc.nimbus.beans.dataset.Record) RecordSet(jp.ossc.nimbus.recset.RecordSet)

Aggregations

Record (jp.ossc.nimbus.beans.dataset.Record)17 RecordList (jp.ossc.nimbus.beans.dataset.RecordList)10 InvocationTargetException (java.lang.reflect.InvocationTargetException)6 DataSet (jp.ossc.nimbus.beans.dataset.DataSet)6 HashMap (java.util.HashMap)4 Iterator (java.util.Iterator)4 List (java.util.List)4 Map (java.util.Map)4 NoSuchPropertyException (jp.ossc.nimbus.beans.NoSuchPropertyException)4 Property (jp.ossc.nimbus.beans.Property)3 SQLException (java.sql.SQLException)2 ArrayList (java.util.ArrayList)2 NestedProperty (jp.ossc.nimbus.beans.NestedProperty)2 Header (jp.ossc.nimbus.beans.dataset.Header)2 RecordSchema (jp.ossc.nimbus.beans.dataset.RecordSchema)2 RecordSet (jp.ossc.nimbus.recset.RecordSet)2 ConnectionFactoryException (jp.ossc.nimbus.service.connection.ConnectionFactoryException)2 PersistentException (jp.ossc.nimbus.service.connection.PersistentException)2 InetAddress (java.net.InetAddress)1 UnknownHostException (java.net.UnknownHostException)1