public boolean moveDown(String id) { Ida ida = idaDAOImpl.findUnique(" from Ida where id=?", id); String hql = " from Ida where _parentId = ? order by seq asc"; List<Ida> list = idaDAOImpl.find(hql, ida.getParentId()); // 查询兄弟节点 int position = list.indexOf(ida); if (position == (list.size() - 1)) { return false; } for (int i = list.size() - 1; i >= 0; i--) { Ida node = list.get(i); if (i == position) { // 于之前的节点seq互换 Ida before = list.get(i + 1); int seq = node.getSeq(); ida.setSeq(before.getSeq()); before.setSeq(seq); idaDAOImpl.save(ida); return true; } else if (i > position) { node.setSeq(node.getSeq() + 1); // 所有当前节点之前的节点,seq-1; } } return false; }
public List<Ida> getNotEmptyByParentId(String parentId) { String hql = "from Ida where _parentId = ? order by seq asc"; List<Ida> idas = idaDAOImpl.find(hql, parentId); List<Ida> result = new ArrayList<Ida>(); for (Ida ida : idas) { if (org.apache.commons.lang.StringUtils.isNotEmpty(ida.getStructName())) { // 过滤名称为空的数据 result.add(ida); } } return result; }
@Override public boolean updateMetadataId(String metadataId, String id) { String hql = " update " + Ida.class.getName() + " set metadataId = ? where id = ?"; idaDAOImpl.batchExecute(hql, metadataId, id); Ida ida = idaDAOImpl.findUniqueBy("id", id); if (ida != null) { // 做一次版本更新 String interfaceId = ida.getInterfaceId(); if (org.apache.commons.lang.StringUtils.isNotEmpty(interfaceId)) { Interface inter = interfaceDAO.findUniqueBy("interfaceId", interfaceId); // 更新版本,只更新一次 versionServiceImpl.editVersion(inter.getVersionId()); } } return true; }
public void deletes(String[] ids) { boolean editFlag = true; for (String id : ids) { if (editFlag) { Ida ida = idaDAOImpl.findUniqueBy("id", id); String interfaceId = ida.getInterfaceId(); if (org.apache.commons.lang.StringUtils.isNotEmpty(interfaceId)) { Interface inter = interfaceDAO.findUniqueBy("interfaceId", interfaceId); // 更新版本,只更新一次 versionServiceImpl.editVersion(inter.getVersionId()); editFlag = false; } } idaDAOImpl.delete(id); } }
@Override public void saveOrUpdate(Ida[] idas) { boolean editFlag = true; for (Ida ida : idas) { if (StringUtils.isEmpty(ida.getHeadId())) { ida.setHeadId(null); } idaDAOImpl.save(ida); if (editFlag) { String interfaceId = ida.getInterfaceId(); if (org.apache.commons.lang.StringUtils.isNotEmpty(interfaceId)) { Interface inter = interfaceDAO.findUniqueBy("interfaceId", interfaceId); // 更新版本,只更新一次 versionServiceImpl.editVersion(inter.getVersionId()); editFlag = false; } } } }
public boolean deleteList(List<Ida> list) { idaDAOImpl.delete(list); boolean editFlag = true; for (int i = 0; i < list.size(); i++) { if (list.get(i) != null) { Ida ida = list.get(i); if (ida != null) { String interfaceId = ida.getInterfaceId(); if (org.apache.commons.lang.StringUtils.isNotEmpty(interfaceId)) { Interface inter = interfaceDAO.findUniqueBy("interfaceId", interfaceId); // 更新版本,只更新一次 versionServiceImpl.editVersion(inter.getVersionId()); editFlag = false; } } } if (!editFlag) break; } return true; }
public Map<String, Ida> genderInterIdaAuto(String interfaceId) { Map<String, Ida> result = new HashMap<String, Ida>(); Ida rootIda = new Ida(); rootIda.setInterfaceId(interfaceId); rootIda.setParentId(null); rootIda.setStructName(Constants.ElementAttributes.ROOT_NAME); rootIda.setStructAlias(Constants.ElementAttributes.ROOT_ALIAS); rootIda.setXpath(Constants.ElementAttributes.ROOT_XPATH); rootIda.setState(Constants.IDA_STATE_COMMON); idaDAOImpl.save(rootIda); result.put(Constants.ElementAttributes.ROOT_NAME, rootIda); Ida reqIda = new Ida(); reqIda.setInterfaceId(interfaceId); reqIda.setParentId(rootIda.getId()); reqIda.setStructName(Constants.ElementAttributes.REQUEST_NAME); reqIda.setStructAlias(Constants.ElementAttributes.REQUEST_ALIAS); reqIda.setXpath(Constants.ElementAttributes.REQUEST_XPATH); reqIda.setSeq(0); reqIda.setState(Constants.IDA_STATE_COMMON); idaDAOImpl.save(reqIda); result.put(Constants.ElementAttributes.REQUEST_NAME, reqIda); Ida resIda = new Ida(); resIda.setInterfaceId(interfaceId); resIda.setParentId(rootIda.getId()); resIda.setSeq(1); resIda.setStructName(Constants.ElementAttributes.RESPONSE_NAME); resIda.setStructAlias(Constants.ElementAttributes.RESPONSE_ALIAS); resIda.setXpath(Constants.ElementAttributes.RESPONSE_XPATH); resIda.setState(Constants.IDA_STATE_COMMON); idaDAOImpl.save(resIda); result.put(Constants.ElementAttributes.RESPONSE_NAME, resIda); return result; }
public IdaMappingBean(Ida ida) { setId(ida.getId()); setStructName(ida.getStructName()); setStructAlias(ida.getStructAlias()); setMetadataId(ida.getMetadataId()); setSeq(ida.getSeq()); setXpath(ida.getXpath()); if (ida.getType() != null) { if (ida.getLength() != null) { setType(ida.getType() + "(" + ida.getLength() + ")"); } else { setType(ida.getType()); } } setScale(ida.getScale()); setLength(ida.getLength()); setRequired(ida.getRequired()); set_parentId(ida.getParentId()); setInterfaceId(ida.getInterfaceId()); setPotUser(ida.getPotUser()); setPotDate(ida.getPotDate()); setHeadId(ida.getHeadId()); setVersion(ida.getVersion()); setRemark(ida.getRemark()); }