use of com.qlangtech.tis.manage.biz.dal.pojo.UploadResource in project tis by qlangtech.
the class UploadResourceDAOImpl method selectByPrimaryKey.
public UploadResource selectByPrimaryKey(Long urId) {
UploadResource key = new UploadResource();
key.setUrId(urId);
UploadResource record = this.load("upload_resource.ibatorgenerated_selectByPrimaryKey", key);
return record;
}
use of com.qlangtech.tis.manage.biz.dal.pojo.UploadResource in project tis by qlangtech.
the class ResSynManager method getSynchronizedOnlineSnapshot.
/**
* 执行将日常配置推送到线上的操作
*
* @param context
* @param module
* @return
* @throws UnsupportedEncodingException
* @throws SchemaFileInvalidException
*/
public Boolean getSynchronizedOnlineSnapshot(final Context context, final BasicModule module) throws Exception {
final SnapshotDomain onlineResDomain = this.getOnlineResDomain();
List<ResSyn> reslist = this.getCompareResult();
List<ResSyn> pushResource = new ArrayList<ResSyn>();
for (ResSyn res : reslist) {
if (!res.isSame()) {
// 若日常和线上相等,则该资源就不推送了
pushResource.add(res);
continue;
}
// pushResource.add(res);
}
if (pushResource.size() < 1) {
module.addErrorMessage(context, "all config resource has been updated already");
return false;
}
// return snapshot;
UploadResource push = null;
List<UploadResource> uploadResources = new ArrayList<UploadResource>();
for (ResSyn res : pushResource) {
if (res.getDaily() == null) {
continue;
}
push = new UploadResource();
push.setResourceType(res.getGetter().getFileName());
push.setContent(res.getDaily().getContent());
push.setMd5Code(res.getDaily().getMd5Code());
uploadResources.add(push);
}
ConfigPush configPush = new ConfigPush();
configPush.setCollection(this.collectionName);
configPush.setSnapshotId(this.getDailyRes().getSnapshot().getSnId());
if (this.getOnlineResDomain() != null) {
configPush.setRemoteSnapshotId(this.getOnlineResDomain().getSnapshot().getSnId());
}
configPush.setUploadResources(uploadResources);
if (onlineResDomain == null) {
// 说明线上还没有第一次发布
Department dpt = new Department();
// dpt.setDptId();
// dpt.setFullName();
Application app = this.runContext.getApplicationDAO().loadFromWriteDB(this.getDailyRes().getAppId());
dpt.setFullName(app.getDptName());
configPush.setDepartment(dpt);
configPush.setReception(app.getRecept());
} else {
configPush.setReception(this.getDailyRes().getSnapshot().getCreateUserName());
}
Writer writer = null;
try {
ByteArrayOutputStream out = new ByteArrayOutputStream();
writer = new OutputStreamWriter(out, BasicModule.getEncode());
HttpConfigFileReader.xstream.toXML(configPush, writer);
writer.flush();
// System.out.println(new String(out.toByteArray(),
// BasicModule.getEncode()));
final URL url = new URL(Config.getTerminatorRepositoryOnline() + "/config/config.ajax?action=app_syn_action&event_submit_do_init_app_from_daily=y");
return HttpUtils.post(url, out.toByteArray(), new PostFormStreamProcess<Boolean>() {
@Override
public ContentType getContentType() {
return ContentType.Multipart_byteranges;
}
@Override
public Boolean p(int status, InputStream stream, Map<String, List<String>> headerFields) {
try {
String result = IOUtils.toString(stream, BasicModule.getEncode());
JSONTokener tokener = new JSONTokener(result);
JSONObject json = new JSONObject(tokener);
JSONArray errs = json.getJSONArray("errormsg");
if (errs.length() > 0) {
for (int i = 0; i < errs.length(); i++) {
module.addErrorMessage(context, errs.getString(i));
}
return false;
}
JSONArray msg = json.getJSONArray("msg");
return true;
} catch (Exception e) {
throw new RuntimeException(e);
}
}
});
} finally {
IOUtils.closeQuietly(writer);
}
}
use of com.qlangtech.tis.manage.biz.dal.pojo.UploadResource in project tis by qlangtech.
the class UploadJarAction method doDownloadGlobalResource.
/**
* 上传全局资源
*
* @param form
* @param nav
* @param context
* @throws Exception
*/
// @Func(PermissionConstant.GLOBAL_DEPENDENCY_UPLOAD)
// public void doUploadGlobalResource(
// @FormGroup("globalres") GlobalResource form, Navigator nav,
// Context context) throws Exception {
//
// Assert.assertNotNull(form);
// Assert.assertNotNull(form.getMemo());
// Assert.assertNotNull(form.getResource());
// if (StringUtils.endsWith(form.getResource().getFieldName(), ".jar")) {
// this.addErrorMessage(context, "文件属性应该为.jar");
// return;
// }
//
// InputStream reader = null;
// try {
//
// reader = form.getResource().getInputStream();
//
// UploadResource solrCoreDependedResource = new UploadResource();
// solrCoreDependedResource.setCreateTime(new Date());
// solrCoreDependedResource.setContent(IOUtils.toByteArray(reader));
// solrCoreDependedResource.setMd5Code(ConfigFileReader
// .md5file(solrCoreDependedResource.getContent()));
// solrCoreDependedResource
// .setResourceType(com.taobao.terminator.runtime.module.screen.GlobalResource.UPLOAD_RESOURCE_TYPE_GLOBAL);
// solrCoreDependedResource.setMemo(form.getMemo());
// Integer newid = this.getUploadResourceDAO().insert(
// solrCoreDependedResource);
//
// this.addActionMessage(context, "成功上传一条全局依赖资源 ID:" + newid);
//
// } finally {
// IOUtils.closeQuietly(reader);
// }
//
// }
// /**
// * 绑定全局资源
// *
// * @param context
// * @throws Exception
// */
// @Func(PermissionConstant.CONFIG_EDIT)
// public void doBindGlobalResource(Context context) throws Exception {
// GlobalAppResource globalAppres = null;
// final String[] uridAry = this.getRequest().getParameterValues("urId");
// StringBuffer idstr = new StringBuffer();
// for (String rid : uridAry) {
// globalAppres = new GlobalAppResource();
// globalAppres.setAppId(this.getAppDomain().getAppid());
// globalAppres.setUrId(Long.parseLong(rid));
// globalAppres.setGmtCreate(new Date());
// globalAppres.setGmtModified(new Date());
// this.getGlobalAppResourceDAO().insertSelective(globalAppres);
// idstr.append("[").append(rid).append("]");
// }
// this.addActionMessage(context, "绑定资源" + idstr + "成功");
// }
// /**
// * 解除全局资源绑定
// *
// * @param context
// * @throws Exception
// */
// @Func(PermissionConstant.CONFIG_EDIT)
// public void doUnbindGlobalResource(Context context) throws Exception {
// final String[] uridAry = this.getRequest().getParameterValues("urId");
// GlobalAppResourceCriteria criteria = null;
// StringBuffer idstr = new StringBuffer();
// for (String rid : uridAry) {
// criteria = new GlobalAppResourceCriteria();
// criteria.createCriteria().andUrIdEqualTo(Long.parseLong(rid)).andAppIdEqualTo(this.getAppDomain().getAppid());
// this.getGlobalAppResourceDAO().deleteByExample(criteria);
// idstr.append("[").append(rid).append("]");
// }
// this.addActionMessage(context, "解除绑定" + idstr + "成功!!!");
// }
/**
* 下载全局依赖资源
*
* @param context
* @throws Exception
*/
public void doDownloadGlobalResource(Context context) throws Exception {
Integer rid = this.getInt("rid");
UploadResource resource = this.getUploadResourceDAO().loadFromWriteDB(new Long(rid));
Assert.assertNotNull("resource can not be null", resource);
Assert.assertNotNull("resource.getContent() can not null", resource.getContent());
Assert.assertEquals("resource type:" + resource.getResourceType() + " rid:" + rid + " is not illegal", com.qlangtech.tis.runtime.module.screen.GlobalResource.UPLOAD_RESOURCE_TYPE_GLOBAL, resource.getResourceType());
Assert.assertEquals(resource.getMd5Code(), ConfigFileReader.md5file(resource.getContent()));
getResponse().setContentType(DownloadResource.JAR_CONTENT_TYPE);
DownloadServlet.setDownloadName(getResponse(), rid + "_" + (System.currentTimeMillis() / 1000) + ".jar");
IOUtils.write(resource.getContent(), getResponse().getOutputStream());
}
Aggregations