Example #1
0
 @Override
 public int create(Config config) {
   Config configFound = configDao.findConfigByKey(config.getKey());
   if (configFound != null) {
     Project project = projectDao.getProject(configFound.getProjectId());
     throw new RuntimeBusinessException(
         "该配置项已存在(project: "
             + (project != null ? project.getName() : "***")
             + ", desc: "
             + configFound.getDesc()
             + ")!");
   }
   Integer currentUserId = SecurityUtils.getCurrentUserId();
   int projectId = config.getProjectId();
   if (config.getCreateUserId() == null) {
     config.setCreateUserId(currentUserId);
   }
   if (config.getModifyUserId() == null) {
     config.setModifyUserId(currentUserId);
   }
   projectDao.lockProject(projectId);
   if (!config.isPrivatee()) {
     config.setPrivatee(isSharedProject(projectId));
   }
   config.setSeq(configDao.getMaxSeq(projectId) + 1);
   return configDao.create(config);
 }
Example #2
0
 private void updateReferencedInstances(
     Config config, List<ConfigInstance> refInstances, ConfigSetType setType) {
   try {
     for (ConfigInstance refInstance : refInstances) {
       int envId = refInstance.getEnvId();
       try {
         if (setType == ConfigSetType.RegisterAndPush) {
           registerAndPush(refInstance.getConfigId(), envId);
         } else if (setType == ConfigSetType.Register) {
           register(refInstance.getConfigId(), envId);
         }
       } catch (RuntimeException e) {
         Config refconfig = getConfig(refInstance.getConfigId());
         operationLogService.createOpLog(
             new OperationLog(
                     OperationTypeEnum.Config_Edit,
                     config.getProjectId(),
                     envId,
                     "同步更新关联引用配置项["
                         + (refconfig != null ? refconfig.getKey() : refInstance.getConfigId())
                         + "]出错,请重新保存该配置.")
                 .key(config.getKey(), ConfigInstance.NO_CONTEXT));
       }
     }
   } catch (Exception e) {
     logger.error("Update config[" + config.getKey() + "]'s referenced configs failed.", e);
   }
 }