Beispiel #1
0
  public static void publishData(WTObject object) throws Exception {
    String filePath = wtTemp + remoteDir + "/";
    try {
      if (object instanceof DataSendOrder) {
        List<WTObject> datas = getDataOrderList((DataSendOrder) object);
        for (WTObject wtObject : datas) {
          if (wtObject instanceof WTPart) { // TODO 处理WTPart是否在发放列表中
            WTPart part = (WTPart) wtObject;

            String directory = filePath + part.getNumber();
            generateXML(part, directory);

            Set<WTPart> allPart = getAllChildPart(part);
            for (WTPart wtPart : allPart) {
              generateXML(wtPart, directory);
            }

            String zipFile = directory + ".zip";
            ZipUtil.zipDir(directory, zipFile);
          }
        }
      }
    } catch (WTException e) {
      e.printStackTrace();
    }
  }
Beispiel #2
0
 public static boolean sendData(WTPart part)
     throws WTException, PropertyVetoException, IOException {
   String filePath = wtTemp + remoteDir + "/";
   String directory = filePath + part.getNumber();
   generateXML(part, directory);
   String zipFile = directory + ".zip";
   ZipUtil.zipDir(directory, zipFile);
   return true;
 }
Beispiel #3
0
  public static String generateXML(WTPart part, String directory)
      throws WTException, PropertyVetoException, IOException {
    File file = new File(directory + "/");
    if (!file.exists()) file.mkdirs();

    DocumentFactory factory = DocumentFactory.getInstance();
    Document document = factory.createDocument();

    Element root = generateRoot(part.getContainerName());
    root.add(generatePart(part, directory));
    document.setRootElement(root);

    OutputFormat format = OutputFormat.createPrettyPrint();
    format.setEncoding("GBK");
    XMLWriter xmlWriter =
        new XMLWriter(
            new OutputStreamWriter(
                new FileOutputStream(directory + part.getNumber() + ".xml"), "GBK"),
            format);
    xmlWriter.write(document);
    xmlWriter.close();

    return null;
  }
Beispiel #4
0
  private static Element generatePart(WTPart parentPart, String fileLocation)
      throws WTException, PropertyVetoException, IOException {
    Element partEle = new BaseElement("Part");
    partEle.addAttribute("PartID", parentPart.getNumber());
    partEle.addAttribute("Version", parentPart.getVersionIdentifier().getValue());
    partEle.addAttribute("Revision", parentPart.getIterationIdentifier().getValue());

    Element attrs = new BaseElement("Attributes");
    attrs.add(new BaseElement("PartName").addText(parentPart.getName()));
    attrs.add(new BaseElement("PartDesc").addText(""));
    // 创建人所属组织
    attrs.add(
        new BaseElement("TeamID")
            .addText(parentPart.getCreator().getPrincipal().getOrganization().getName()));
    attrs.add(new BaseElement("CreatedBy").addText(parentPart.getCreatorFullName()));
    attrs.add(new BaseElement("UpdatedBy").addText(parentPart.getModifierFullName()));
    attrs.add(
        new BaseElement("CreatedTime")
            .addText(
                dateFormat.format(
                    new Date(PersistenceHelper.getCreateStamp(parentPart).getTime()))));
    attrs.add(
        new BaseElement("LastUpdated")
            .addText(
                dateFormat.format(
                    new Date(PersistenceHelper.getModifyStamp(parentPart).getTime()))));
    attrs.add(
        new BaseElement("Unit")
            .addText(parentPart.getDefaultUnit().getLocalizedMessage(Locale.CHINA)));
    attrs.add(
        new BaseElement("PartType").addText(parentPart.getPartType().getDisplay(Locale.CHINA)));

    // 开始获取软属性
    List<Element> ibaList = getIBAElement(parentPart);
    for (Element element : ibaList) {
      attrs.add(element);
      ;
    }
    partEle.add(attrs);

    QueryResult partUseBOMQR =
        PersistenceHelper.manager.navigate(
            parentPart, EPMBuildRule.BUILD_SOURCE_ROLE, EPMBuildRule.class);
    while (partUseBOMQR.hasMoreElements()) { // CADCOMPONENT || CADASSEMBLY || CADDRAWING
      EPMDocument parentEpm = (EPMDocument) partUseBOMQR.nextElement();
      // 装配或CAD部件时写CAD元素
      if (!parentEpm.getDocType().toString().equals("CADCOMPONENT")
          && !parentEpm.getDocType().toString().equals("CADASSEMBLY")) continue;

      if (parentEpm.getDocType().toString().equals("CADASSEMBLY")) { // 装配,才有使用关系
        Element partUses = new BaseElement("PartUses");

        QueryResult epmUseQR =
            PersistenceHelper.manager.navigate(
                parentEpm, EPMMemberLink.USES_ROLE, EPMMemberLink.class, false);
        while (epmUseQR.hasMoreElements()) {
          EPMMemberLink memberLink = (EPMMemberLink) epmUseQR.nextElement();
          long amount = Math.round(memberLink.getQuantity().getAmount());
          EPMDocumentMaster childEpmMaster = (EPMDocumentMaster) memberLink.getUses();
          EPMDocument childEpm = getLatestObject(childEpmMaster);
          Matrix4d matrix4d = memberLink.getTransform().toMatrix4d();

          Element usePart = new BaseElement("Part");
          usePart.addAttribute("PartID", childEpm.getNumber());
          usePart.addAttribute("PartVersion", childEpm.getVersionIdentifier().getValue());
          usePart.addAttribute("Amount", amount + "");
          for (long i = 1; i <= amount; i++) {
            Element partIntance = new BaseElement("PartIntance");
            partIntance.addAttribute("InstanceName", childEpm.getNumber() + "." + i);

            Element transform = matrix4d2Transform(matrix4d);
            partIntance.add(transform);

            Element cfgInfo = new BaseElement("CfgInfo");
            partIntance.add(cfgInfo);

            usePart.add(partIntance);
          }
          partUses.add(usePart);
        }
        partEle.add(partUses);
      }

      // 写部件与CAD文档的关系
      Element partDescBy = new BaseElement("PartDescBy");
      Element cadDocument = getCADElement(parentEpm, fileLocation);
      partDescBy.add(cadDocument);
      partEle.add(partDescBy);

      // 部件与普通文档关系
      Element partRef = new BaseElement("PartRef");
      QueryResult docQR = PartDocHelper.service.getAssociatedDocuments(parentPart);
      while (docQR.hasMoreElements()) {
        Object object = (Object) docQR.nextElement();
        if (object instanceof WTDocument) {
          WTDocument childDoc = (WTDocument) object;
          Element document = getWTDocElement(childDoc, fileLocation);
          partRef.add(document);
        }
      }

      partEle.add(partRef);
    }
    return partEle;
  }