Search in sources :

Example 1 with UploadResource

use of com.qlangtech.tis.manage.biz.dal.pojo.UploadResource in project tis by qlangtech.

the class ResSynManager method createNewResource.

/**
 * @param context
 * @param uploadContent
 * @param md5
 * @param fileGetter
 * @param messageHandler
 * @param runContext
 * @return 新创建的主键
 * @throws UnsupportedEncodingException
 * @throws SchemaFileInvalidException
 */
public static Integer createNewResource(Context context, ISchemaPluginContext schemaPluginContext, final byte[] uploadContent, final String md5, PropteryGetter fileGetter, IMessageHandler messageHandler, RunContext runContext) throws SchemaFileInvalidException {
    UploadResource resource = new UploadResource();
    resource.setContent(uploadContent);
    resource.setCreateTime(new Date());
    resource.setResourceType(fileGetter.getFileName());
    resource.setMd5Code(md5);
    ConfigFileValidateResult validateResult = fileGetter.validate(schemaPluginContext, resource);
    // 校验文件格式是否正确,通用用DTD来校验
    if (!validateResult.isValid()) {
        messageHandler.addErrorMessage(context, ERROR_MSG_SCHEMA_TITLE);
        messageHandler.addErrorMessage(context, validateResult.getValidateResult());
        throw new SchemaFileInvalidException(validateResult.getValidateResult());
    }
    return runContext.getUploadResourceDAO().insertSelective(resource);
}
Also used : UploadResource(com.qlangtech.tis.manage.biz.dal.pojo.UploadResource)

Example 2 with UploadResource

use of com.qlangtech.tis.manage.biz.dal.pojo.UploadResource in project tis by qlangtech.

the class SnapshotDomainUtils method mockEmployeeSnapshotDomain.

public static SnapshotDomain mockEmployeeSnapshotDomain() throws Exception {
    SnapshotDomain snapshotDomain = new SnapshotDomain();
    try (InputStream i = SnapshotDomainUtils.class.getResourceAsStream("search4employee-schema")) {
        Objects.requireNonNull(i, "schema stream can not be null");
        UploadResource schema = new UploadResource();
        schema.setContent(IOUtils.toByteArray(i));
        schema.setMd5Code(ConfigFileReader.md5file(schema.getContent()));
        snapshotDomain.setSolrSchema(schema);
    }
    try (InputStream i = SnapshotDomainUtils.class.getResourceAsStream("search4employee-solrconfig")) {
        Objects.requireNonNull(i, "solrconfig stream can not be null");
        UploadResource solrCfg = new UploadResource();
        solrCfg.setContent(IOUtils.toByteArray(i));
        solrCfg.setMd5Code(ConfigFileReader.md5file(solrCfg.getContent()));
        snapshotDomain.setSolrConfig(solrCfg);
    }
    // System.out.println(snapshotDomain);
    return snapshotDomain;
}
Also used : InputStream(java.io.InputStream) UploadResource(com.qlangtech.tis.manage.biz.dal.pojo.UploadResource)

Example 3 with UploadResource

use of com.qlangtech.tis.manage.biz.dal.pojo.UploadResource in project tis by qlangtech.

the class TestSchemaAction method testDoSaveByExpertModel.

/**
 * 测试专家模式Schema保存, 将mall_id类型由string改成test类型,并且去掉了一个动态字段pt_*
 *
 * @throws Exception
 */
public void testDoSaveByExpertModel() throws Exception {
    // event_submit_do_save_by_expert_model: y
    request.setParameter("emethod", "saveByExpertModel");
    request.setParameter("action", "schema_action");
    // request.addHeader("appname", collection);
    setCollection(collection);
    try (InputStream post = this.getClass().getResourceAsStream("schema-action-do-save-by-expert-model.json")) {
        request.setContent(IOUtils.toByteArray(post));
    }
    ActionProxy proxy = getActionProxy();
    String result = proxy.execute();
    assertEquals("SchemaAction_ajax", result);
    AjaxValve.ActionExecResult aResult = showBizResult();
    assertNotNull(aResult);
    assertTrue(aResult.isSuccess());
    // this.verifyAll();
    SchemaAction.CreateSnapshotResult bizResult = (SchemaAction.CreateSnapshotResult) aResult.getBizResult();
    assertNotNull(bizResult);
    Integer newSnapshotId = bizResult.getNewId();
    assertTrue("newSnapshotId can not be null", newSnapshotId > 0);
    SnapshotDomain snapshotView = runContext.getSnapshotViewDAO().getView(newSnapshotId);
    assertNotNull("snapshotView can not be null", snapshotView);
    UploadResource solrSchema = snapshotView.getSolrSchema();
    String mallIdTypeModifiedXml = StringUtils.remove(new String(solrSchema.getContent(), TisUTF8.get()), '\r');
    try (InputStream input = this.getClass().getResourceAsStream("schema-action-do-save-by-expert-model-modify-mallid-type-assert.xml")) {
        assertNotNull(input);
        String mallIdTypeModifiedXmlExpect = StringUtils.trimToEmpty(IOUtils.toString(input, TisUTF8.get()));
        assertEquals(mallIdTypeModifiedXmlExpect, StringUtils.trimToEmpty(mallIdTypeModifiedXml));
    }
// JsonUtil.assertJSONEqual(TestSchemaAction.class, "schema-action-do-save-by-expert-model-modify-mallid-type-assert.xml"
// , mallIdTypeModifiedXml, (msg, e, a) -> {
// assertEquals(msg, e, a);
// });
}
Also used : ActionProxy(com.opensymphony.xwork2.ActionProxy) SnapshotDomain(com.qlangtech.tis.manage.common.SnapshotDomain) InputStream(java.io.InputStream) AjaxValve(com.qlangtech.tis.manage.common.valve.AjaxValve) UploadResource(com.qlangtech.tis.manage.biz.dal.pojo.UploadResource)

Example 4 with UploadResource

use of com.qlangtech.tis.manage.biz.dal.pojo.UploadResource in project tis by qlangtech.

the class UploadJarAction method processFormItem.

public static Snapshot processFormItem(RunContext runContext, ConfigContentGetter getter, Snapshot snapshot) throws IOException {
    // InputStream reader = null;
    // try {
    // reader = getter.formItem.getInputStream();
    UploadResource solrCoreDependedResource = new UploadResource();
    solrCoreDependedResource.setCreateTime(new Date());
    solrCoreDependedResource.setContent(getter.getContent());
    solrCoreDependedResource.setMd5Code(ConfigFileReader.md5file(solrCoreDependedResource.getContent()));
    solrCoreDependedResource.setResourceType(getter.getterStrategy.getFileName());
    Integer newid = runContext.getUploadResourceDAO().insertSelective(solrCoreDependedResource);
    return getter.getterStrategy.createNewSnapshot(newid, snapshot);
}
Also used : UploadResource(com.qlangtech.tis.manage.biz.dal.pojo.UploadResource) Date(java.util.Date)

Example 5 with UploadResource

use of com.qlangtech.tis.manage.biz.dal.pojo.UploadResource in project tis by qlangtech.

the class TestGetAppConfigBySnid method testGetResource.

public void testGetResource() {
    try {
        SnapshotDomain domain = HttpConfigFileReader.getResource("http://localhost", 222);
        UploadResource resource = domain.getSolrSchema();
        Assert.assertNotNull(resource);
        Assert.assertNotNull(resource.getContent());
    } catch (RepositoryException e) {
        Assert.assertFalse(e.getMessage(), true);
    }
}
Also used : SnapshotDomain(com.qlangtech.tis.manage.common.SnapshotDomain) UploadResource(com.qlangtech.tis.manage.biz.dal.pojo.UploadResource) RepositoryException(com.qlangtech.tis.manage.common.RepositoryException)

Aggregations

UploadResource (com.qlangtech.tis.manage.biz.dal.pojo.UploadResource)13 SnapshotDomain (com.qlangtech.tis.manage.common.SnapshotDomain)4 RepositoryException (com.qlangtech.tis.manage.common.RepositoryException)2 InputStream (java.io.InputStream)2 ActionProxy (com.opensymphony.xwork2.ActionProxy)1 Application (com.qlangtech.tis.manage.biz.dal.pojo.Application)1 Department (com.qlangtech.tis.manage.biz.dal.pojo.Department)1 Snapshot (com.qlangtech.tis.manage.biz.dal.pojo.Snapshot)1 AjaxValve (com.qlangtech.tis.manage.common.valve.AjaxValve)1 IOException (java.io.IOException)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 MalformedURLException (java.net.MalformedURLException)1 URL (java.net.URL)1 Date (java.util.Date)1 JSONArray (org.json.JSONArray)1 JSONObject (org.json.JSONObject)1 JSONTokener (org.json.JSONTokener)1