Java tutorial
/* * * * Copyright 1999-2011 jeap Group Holding Ltd. * * * * Licensed under the Apache License, Version 2.0 (the "License"); * * you may not use this file except in compliance with the License. * * You may obtain a copy of the License at * * * * http://www.apache.org/licenses/LICENSE-2.0 * * * * Unless required by applicable law or agreed to in writing, software * * distributed under the License is distributed on an "AS IS" BASIS, * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * * See the License for the specific language governing permissions and * * limitations under the License. * */ package com.easysoft.build.manager; import com.easysoft.build.dao.*; import com.easysoft.build.model.*; import com.easysoft.build.vo.BuildConfigInfoSearchBean; import com.easysoft.framework.db.PageOption; import com.easysoft.framework.utils.DateUtil; import org.apache.commons.lang3.StringUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Scope; import org.springframework.context.annotation.ScopedProxyMode; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import java.text.DecimalFormat; import java.text.SimpleDateFormat; import java.util.Calendar; import java.util.Date; import java.util.List; @Service("buildConfigInfoService") @Scope(proxyMode = ScopedProxyMode.TARGET_CLASS) @Transactional public class BuildConfigInfoService { @Autowired private BuildConfigInfoDao buildConfigInfoDao; @Autowired private BuildConfigInfoLogDao buildConfigInfoLogDao; @Autowired private RespInfoDao respInfoDao; @Autowired private PrivatePackLogDao privatePackLogDao; @Autowired private DeployPackInfoDao deployPackInfoDao; @Autowired private DeployPackInfoLogDao deployPackInfoLogDao; public void saveBcConfigInBuilding(BuildConfig config) { BuildConfigInfo bc = new BuildConfigInfo(); RepInfo ri = respInfoDao.getRespInfoByName(config.getVersion()); bc.setRi(ri); bc.setBuildFileName(config.getId()); bc.setStatus("0"); bc.setAdder(config.getDevelopers()); bc.setAddTime(new Date()); bc.setBuildDepends(config.listDepends()); bc.setBuildComments(config.getComment()); bc.setIncludsFiles(config.getFiles()); bc.setHasSql(config.getHas_sql()); bc.setSqlFiles(config.getSqlFiles()); bc.setVpNames(config.getVps()); bc.setIncludsModules(config.getModules()); buildConfigInfoDao.saveBuildConfigInfo(bc); // BuildConfigInfoLog log = new BuildConfigInfoLog(); log.setRi(ri); log.setBc(bc); log.setOperater(config.getDevelopers()); log.setOperaterCode("0"); log.setOperaterName("??"); log.setOperaterTime(new Date()); buildConfigInfoLogDao.saveBuildConfigInfoLog(log); } public List<BuildConfigInfo> getBuildConfigInfoList(BuildConfigInfoSearchBean searchBean, PageOption pageOption, String curBranch) { List<BuildConfigInfo> results = buildConfigInfoDao.getBuildConfigInfoList(searchBean, pageOption, curBranch); pageOption.setData(results); return results; } public void saveBcConfigInPrivatePacking(String userName, String branch, String fileName) { String buildName = fileName.substring(0, fileName.indexOf(".zip")); RepInfo ri = respInfoDao.getRespInfoByName(branch); BuildConfigInfo bc = buildConfigInfoDao.getBuildConfigInfoByNameNoCancel(buildName, ri); if (bc != null) { PrivatePackLog plog = new PrivatePackLog(); plog.setBc(bc); plog.setRi(ri); plog.setDepends(bc.getBuildDepends()); plog.setTakePersonName(userName); plog.setTakeTime(new Date()); privatePackLogDao.savePrivatePackLog(plog); } } public void saveBcConfigInDeployPacking(BuildConfig config, String deployer) throws Exception { //?? RepInfo ri = respInfoDao.getRespInfoByName(config.getVersion()); BuildConfigInfo bc = buildConfigInfoDao.getBuildConfigInfoByNameNoCancel(config.getId(), ri); if (bc != null) { bc.setStatus("5"); bc.setDeployUsers(deployer); bc.setDeployTime(new Date()); String patchName = ""; //?BUG if ("1".equals(ri.getIsWeekbug())) { patchName = makeWeekBugDeployPackName(ri); } else { //? ? Date curDate = Calendar.getInstance().getTime(); patchName = ri.getBand() + "." + ri.getVersionNo() + ri.getSpNo() + "." + (ri.getVersionPattern() == null ? "" : new SimpleDateFormat(ri.getVersionPattern()).format(curDate)) + "01" + "." + ri.getVersionSuffix(); } DeployPackInfo di = deployPackInfoDao.getDeployPackInfoByName(patchName, ri.getId()); if (di == null) { DeployPackInfo dinew = new DeployPackInfo(); dinew.setRi(ri); dinew.setCreateTime(new Date()); dinew.setDeployPackName(patchName); deployPackInfoDao.saveDeployPackInfo(dinew); bc.setBd(dinew); } else { di.setCreateTime(new Date()); bc.setBd(di); } buildConfigInfoDao.saveBuildConfigInfo(bc); //?? updateDeploys(config, ri); // BuildConfigInfoLog log = new BuildConfigInfoLog(); log.setRi(ri); log.setBc(bc); log.setOperater(deployer); log.setOperaterCode("5"); log.setOperaterName("?"); log.setOperaterTime(new Date()); buildConfigInfoLogDao.saveBuildConfigInfoLog(log); } } /* @Override protected BaseExtendDao getDao() { return buildConfigInfoDao; } public List<BuildConfigInfo> getBuildConfigInfoByDeployId(String id,String curBranch){ return buildConfigInfoDao.getBuildConfigInfoByDeployId(id,curBranch); } public List<BuildConfigInfo> getBuildConfigInfoExportList(BuildConfigInfoSearchBean searchBean,String curBranch){ return buildConfigInfoDao.getBuildConfigInfoExportList(searchBean,curBranch); } public BuildConfigInfo getBuildConfigInfo(String id){ return buildConfigInfoDao.getBuildConfigInfo(Long.valueOf(id)); } public void saveBuildConfigInfo(BuildConfigInfo bc){ buildConfigInfoDao.saveBuildConfigInfo(bc); } public void delBuildConfigInfo(String id){ BuildConfigInfo bc = (BuildConfigInfo)buildConfigInfoDao.getBuildConfigInfo(Long.valueOf(id)); if(bc!=null){ buildConfigInfoDao.delBuildConfigInfo(bc); } } */ public void saveBcConfigInPasstesting(BuildConfig config) { RepInfo ri = respInfoDao.getRespInfoByName(config.getVersion()); BuildConfigInfo bc = buildConfigInfoDao.getBuildConfigInfoByNameNoCancel(config.getId(), ri); if (bc != null) { bc.setStatus("3"); bc.setPassTester(config.getTesters()); bc.setPassTestTime(new Date()); buildConfigInfoDao.saveBuildConfigInfo(bc); // BuildConfigInfoLog log = new BuildConfigInfoLog(); log.setRi(ri); log.setBc(bc); log.setOperater(config.getTesters()); log.setOperaterCode("3"); log.setOperaterName(""); log.setOperaterTime(new Date()); buildConfigInfoLogDao.saveBuildConfigInfoLog(log); } } public void saveBcConfigInCancelTesting(BuildConfig config, String tester) { RepInfo ri = respInfoDao.getRespInfoByName(config.getVersion()); BuildConfigInfo bc = buildConfigInfoDao.getBuildConfigInfoByNameNoCancel(config.getId(), ri); if (bc != null) { bc.setStatus("2"); bc.setCancelTester(tester); bc.setCancelTestTime(new Date()); buildConfigInfoDao.saveBuildConfigInfo(bc); // BuildConfigInfoLog log = new BuildConfigInfoLog(); log.setRi(ri); log.setBc(bc); log.setOperater(tester); log.setOperaterCode("2"); log.setOperaterName("?"); log.setOperaterTime(new Date()); buildConfigInfoLogDao.saveBuildConfigInfoLog(log); } } public void saveBcConfigInStartesting(BuildConfig config) { RepInfo ri = respInfoDao.getRespInfoByName(config.getVersion()); BuildConfigInfo bc = buildConfigInfoDao.getBuildConfigInfoByNameNoCancel(config.getId(), ri); if (bc != null) { bc.setStatus("1"); bc.setStartTester(config.getTesters()); bc.setStartTestTime(new Date()); buildConfigInfoDao.saveBuildConfigInfo(bc); // BuildConfigInfoLog log = new BuildConfigInfoLog(); log.setRi(ri); log.setBc(bc); log.setOperater(config.getTesters()); log.setOperaterCode("1"); log.setOperaterName(""); log.setOperaterTime(new Date()); buildConfigInfoLogDao.saveBuildConfigInfoLog(log); } } public void saveBcConfigInCancelBuilding(BuildConfig config, String tester) { //?? RepInfo ri = respInfoDao.getRespInfoByName(config.getVersion()); BuildConfigInfo bc = buildConfigInfoDao.getBuildConfigInfoByNameNoCancel(config.getId(), ri); if (bc != null) { bc.setStatus("4"); bc.setBuildDeleter(tester); bc.setBuildDeleteTime(new Date()); buildConfigInfoDao.saveBuildConfigInfo(bc); //?? updateDeploys(config, ri); // BuildConfigInfoLog log = new BuildConfigInfoLog(); log.setRi(ri); log.setBc(bc); log.setOperater(tester); log.setOperaterCode("4"); log.setOperaterName("?"); log.setOperaterTime(new Date()); buildConfigInfoLogDao.saveBuildConfigInfoLog(log); } } public void saveBcConfigInEnDeployPacking(String userName, String branch, String fileName) { String packName = fileName.substring(0, fileName.indexOf(".zip")); RepInfo ri = respInfoDao.getRespInfoByName(branch); DeployPackInfo di = deployPackInfoDao.getDeployPackInfoByName(packName, ri.getId()); if (di != null) { DeployPackInfoLog dlog = new DeployPackInfoLog(); dlog.setDp(di); dlog.setRi(ri); dlog.setTakePersonName(userName); dlog.setTakeTime(new Date()); dlog.setTakeType("1"); deployPackInfoLogDao.saveDeployPackInfoLog(dlog); } } public void saveBcConfigInDeployPacking(String userName, String branch, String fileName) { String packName = fileName.substring(0, fileName.indexOf(".zip")); RepInfo ri = respInfoDao.getRespInfoByName(branch); DeployPackInfo di = deployPackInfoDao.getDeployPackInfoByName(packName, ri.getId()); if (di != null) { DeployPackInfoLog dlog = new DeployPackInfoLog(); dlog.setDp(di); dlog.setRi(ri); dlog.setTakePersonName(userName); dlog.setTakeTime(new Date()); dlog.setTakeType("0"); deployPackInfoLogDao.saveDeployPackInfoLog(dlog); } } public void updateDeploys(BuildConfig config, RepInfo ri) { List<BuildConfigInfo> list = buildConfigInfoDao.getDependsBuildConfigInfoList(config.getId(), ri.getId()); String depends = ""; String dnew = ""; for (BuildConfigInfo bci : list) { dnew = ""; depends = bci.getBuildDepends(); String[] dArray = depends.split(";"); for (String d : dArray) { if (config.getId().equals(d)) { continue; } else { if (StringUtils.isEmpty(dnew)) { dnew = d; } else { dnew = dnew + ";" + d; } } } bci.setBuildDepends(dnew); buildConfigInfoDao.saveBuildConfigInfo(bci); } } //?/?BUG??? //2 ?BUGBFS.V10.6.00. + 02/03/04...(?) private static String makeWeekBugDeployPackName(RepInfo ri) throws Exception { Date curDate = DateUtil.toDate(ri.getCreateDate(), "yyyyMMdd");// ? String dateVersion = (ri.getVersionPattern() == null ? "" : new SimpleDateFormat(ri.getVersionPattern()).format(curDate));// ?? // ???? Calendar cal = Calendar.getInstance(); int dayOfWeek = cal.get(Calendar.DAY_OF_WEEK); // ??02-08 String smallVersion = (dayOfWeek == Calendar.SUNDAY) ? "08" // 1 : new DecimalFormat("00").format(dayOfWeek);// 2-7 String patchName = ri.getBand() + "." + ri.getVersionNo() + ri.getSpNo() + "." + dateVersion + smallVersion + "." + ri.getVersionSuffix(); return patchName; } }