Search in sources :

Example 11 with DataSet

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

the class HttpResponseImplTest method testSetObject.

/**
 * HttpResponseのストリームを設定、取得するテスト。
 * <p>
 * 条件:
 * <ul>
 * <li>XMLストリームデータをデータセットに変換して取得する</li>
 * <li>次の内容をDataSetXMLConverterで変換する<BR>
 * <PRE>
 * <?xml version="1.0" encoding="UTF-8"?>
 *  <dataSet>
 *   <schema>
 *    <header name="TestHeader">
 *     :A,java.util.Date,
 *     "jp.ossc.nimbus.util.converter.DateFormatConverter{ConvertType=2;Format="yyyy-MM-DD"}",
 *     "jp.ossc.nimbus.util.converter.DateFormatConverter{ConvertType=1;Format="yyyy-MM-DD"}",
 *     "@value@ != null"
 *     :B,java.lang.String,,,
 *    </header>
 *   </schema>
 *    <header name="TestHeader"><A>2008-01-28</A><B>TestValue</B></header></dataSet>
 * <PRE></li>
 * <li>上記のストリームデータとコンバータをプロパティに設定して、<BR>
 * HttpResponse#getObjectを実行</li>
 * </ul>
 * 確認:
 * <ul>
 * <li>正しい値が返ってくることを確認</li>
 * </ul>
 */
public void testSetObject() {
    try {
        HttpResponseImpl res = new HttpResponseImpl();
        // CharacterEncodingを設定しておく
        res.headerMap = new HashMap();
        String[] vals = new String[] { "application/xml;charset=Shift_JIS" };
        res.headerMap.put("Content-Type", vals);
        String inxml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" + "<dataSet><schema><header name=\"TestHeader\">" + ":A,java.util.Date," + "\"jp.ossc.nimbus.util.converter.DateFormatConverter{ConvertType=2;Format=\"yyyy-MM-DD\"}\"," + "\"jp.ossc.nimbus.util.converter.DateFormatConverter{ConvertType=1;Format=\"yyyy-MM-DD\"}\"," + "\"@value@ != null\"\n:B,java.lang.String,,," + "</header></schema><header name=\"TestHeader\">" + "<A>2008-01-28</A><B>TestValue</B></header></dataSet>";
        // 入力ストリームとコンバーターをプロパティにセット
        InputStream is = new ByteArrayInputStream(inxml.getBytes());
        res.setInputStream(is);
        DataSetXMLConverter conv = new DataSetXMLConverter(DataSetXMLConverter.XML_TO_DATASET);
        res.setStreamConverter(conv);
        // 
        DataSet dataset = (DataSet) res.getObject();
        assertEquals("TestHeader", dataset.getHeader("TestHeader").getName());
        assertEquals(":A,java.util.Date," + "\"jp.ossc.nimbus.util.converter.DateFormatConverter{ConvertType=2;Format=\"yyyy-MM-DD\"}\"," + "\"jp.ossc.nimbus.util.converter.DateFormatConverter{ConvertType=1;Format=\"yyyy-MM-DD\"}\"," + "\"@value@ != null\"\n:B,java.lang.String,,,", dataset.getHeader("TestHeader").getSchema());
        assertEquals("2008-01-28", dataset.getHeader("TestHeader").getFormatProperty("A"));
        assertEquals("TestValue", dataset.getHeader("TestHeader").getProperty("B"));
    } catch (PropertySchemaDefineException e) {
        e.printStackTrace();
        fail("例外発生");
    } catch (ConvertException e) {
        e.printStackTrace();
        fail("例外発生");
    }
}
Also used : PropertySchemaDefineException(jp.ossc.nimbus.beans.dataset.PropertySchemaDefineException) ConvertException(jp.ossc.nimbus.util.converter.ConvertException) DataSet(jp.ossc.nimbus.beans.dataset.DataSet) DataSetXMLConverter(jp.ossc.nimbus.util.converter.DataSetXMLConverter)

Example 12 with DataSet

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

the class DataSetXpathConverterTest method testConvertToObject.

public void testConvertToObject() {
    DataSet inputDataSet = new DataSetXPathConverterTestDataSet();
    // 初期データ設定
    Header inputHeader = inputDataSet.getHeader();
    inputHeader.setProperty(DataSetXPathConverterTestDataSet.PROPERTY0, "PROP0");
    inputHeader.setParseProperty(DataSetXPathConverterTestDataSet.PROPERTY1, "PROP1");
    BindingStreamConverter converter = new DataSetXpathConverter();
    DataSetXPathConverterTestDataSet dataSet = (DataSetXPathConverterTestDataSet) converter.convertToObject(createTestData(), inputDataSet);
    Header header = dataSet.getHeader();
    RecordList recordList = dataSet.getRecordList();
    // 初期データ取得
    Assert.assertEquals("PROP0", header.get(DataSetXPathConverterTestDataSet.PROPERTY0));
    // 属性取得
    Assert.assertEquals("ATTR", header.get(DataSetXPathConverterTestDataSet.PROPERTY1));
    // 属性値による指定ノード取得
    Assert.assertEquals("テキスト2-3", header.get(DataSetXPathConverterTestDataSet.PROPERTY2));
    // ノードインデックスによる指定ノード取得
    Assert.assertEquals("ATTR1", header.get(DataSetXPathConverterTestDataSet.PROPERTY3));
    // 子ノード取得
    for (int i = 0; i < recordList.size(); i++) {
        Record record = (Record) recordList.get(i);
        Assert.assertEquals("テキスト" + (i + 1) + "-1", record.get(DataSetXPathConverterTestDataSet.PROPERTY4));
        Assert.assertEquals("テキスト" + (i + 1) + "-2", record.get(DataSetXPathConverterTestDataSet.PROPERTY5));
        Assert.assertEquals("テキスト" + (i + 1) + "-3", record.get(DataSetXPathConverterTestDataSet.PROPERTY6));
    }
}
Also used : Header(jp.ossc.nimbus.beans.dataset.Header) RecordList(jp.ossc.nimbus.beans.dataset.RecordList) DataSet(jp.ossc.nimbus.beans.dataset.DataSet) Record(jp.ossc.nimbus.beans.dataset.Record)

Example 13 with DataSet

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

the class DatabaseAuthenticateStoreService method activate.

public Object activate(HttpServletRequest request, Object authenticatedKey) throws AuthenticateStoreException {
    if (selectQueryOnFindUser == null) {
        return null;
    }
    Connection con = null;
    try {
        con = connectionFactory.getConnection();
    } catch (ConnectionFactoryException e) {
        throw new AuthenticateStoreException(e);
    }
    try {
        Object authenticatedInfo = null;
        if (selectQueryOnFindUser != null) {
            if (authenticatedInfoClass != null) {
                List list = (List) persistentManager.loadQuery(con, selectQueryOnFindUser, createInput(request, null, authenticatedKey), authenticatedInfoClass);
                if (list.size() == 0) {
                    return null;
                }
                authenticatedInfo = list.get(0);
            } else {
                if (authenticatedInfoTemplate instanceof DataSet) {
                    authenticatedInfo = ((DataSet) authenticatedInfoTemplate).cloneSchema();
                } else if (authenticatedInfoTemplate instanceof RecordList) {
                    authenticatedInfo = ((RecordList) authenticatedInfoTemplate).cloneSchema();
                } else if (authenticatedInfoTemplate instanceof Record) {
                    authenticatedInfo = ((Record) authenticatedInfoTemplate).cloneSchema();
                } else if (authenticatedInfoTemplate instanceof Cloneable) {
                    try {
                        authenticatedInfo = authenticatedInfoTemplate.getClass().getMethod("clone", (Class[]) null).invoke(authenticatedInfoTemplate, (Object[]) null);
                    } catch (NoSuchMethodException e) {
                        throw new AuthenticateStoreException(e);
                    } catch (IllegalAccessException e) {
                        throw new AuthenticateStoreException(e);
                    } catch (InvocationTargetException e) {
                        throw new AuthenticateStoreException(e);
                    }
                }
                authenticatedInfo = persistentManager.loadQuery(con, selectQueryOnFindUser, createInput(request, null, authenticatedKey), authenticatedInfo);
            }
        }
        if (authenticatedInfo != null && updateQueryOnActivate != null) {
            if (request.getSession(false) == null) {
                request.getSession(true);
            }
            persistentManager.persistQuery(con, updateQueryOnActivate, createInput(request, null, authenticatedInfo));
        }
        return authenticatedInfo;
    } catch (PersistentException e) {
        throw new AuthenticateStoreException(e);
    } finally {
        try {
            con.close();
        } catch (SQLException e) {
        }
    }
}
Also used : PersistentException(jp.ossc.nimbus.service.connection.PersistentException) DataSet(jp.ossc.nimbus.beans.dataset.DataSet) SQLException(java.sql.SQLException) Connection(java.sql.Connection) ConnectionFactoryException(jp.ossc.nimbus.service.connection.ConnectionFactoryException) InvocationTargetException(java.lang.reflect.InvocationTargetException) RecordList(jp.ossc.nimbus.beans.dataset.RecordList) RecordList(jp.ossc.nimbus.beans.dataset.RecordList) List(java.util.List) Record(jp.ossc.nimbus.beans.dataset.Record)

Aggregations

DataSet (jp.ossc.nimbus.beans.dataset.DataSet)13 RecordList (jp.ossc.nimbus.beans.dataset.RecordList)8 Record (jp.ossc.nimbus.beans.dataset.Record)6 InvocationTargetException (java.lang.reflect.InvocationTargetException)5 Iterator (java.util.Iterator)5 Header (jp.ossc.nimbus.beans.dataset.Header)5 PropertySchemaDefineException (jp.ossc.nimbus.beans.dataset.PropertySchemaDefineException)5 HashMap (java.util.HashMap)4 List (java.util.List)4 Map (java.util.Map)4 NoSuchPropertyException (jp.ossc.nimbus.beans.NoSuchPropertyException)4 Property (jp.ossc.nimbus.beans.Property)4 ConvertException (jp.ossc.nimbus.util.converter.ConvertException)4 SQLException (java.sql.SQLException)3 ArrayList (java.util.ArrayList)3 NestedProperty (jp.ossc.nimbus.beans.NestedProperty)3 LinkedHashMap (java.util.LinkedHashMap)2 HttpClientFactory (jp.ossc.nimbus.service.http.HttpClientFactory)2 HttpRequest (jp.ossc.nimbus.service.http.HttpRequest)2 HttpClientImpl (jp.ossc.nimbus.service.http.httpclient.HttpClientFactoryService.HttpClientImpl)2