Example #1
0
  private static Element getCADElement(EPMDocument epmDocument, String fileLocation)
      throws WTException, PropertyVetoException, IOException {
    Element cadDocument = new BaseElement("CADDocument");
    cadDocument.addAttribute("DocID", epmDocument.getNumber());
    cadDocument.addAttribute("Revision", epmDocument.getIterationIdentifier().getValue());
    cadDocument.addAttribute("Version", epmDocument.getVersionIdentifier().getValue());

    epmDocument = (EPMDocument) ContentHelper.service.getContents(epmDocument);
    ContentItem contentHolder = ContentHelper.getPrimary(epmDocument);
    ApplicationData applicationdataPrimary = (ApplicationData) contentHolder;

    String docType = "CATPart";
    if (epmDocument.getDocType().toString().equals("CADASSEMBLY")) docType = "CATProd";
    else if (epmDocument.getDocType().toString().equals("CADDRAWING")) docType = "CATDraw";

    Element cadAttr = new BaseElement("Attributes");
    cadAttr.add(new BaseElement("DocName").addText(applicationdataPrimary.getFileName()));
    cadAttr.add(new BaseElement("DocType").addText(docType));
    cadAttr.add(
        new BaseElement("TeamID")
            .addText(epmDocument.getCreator().getPrincipal().getOrganization().getName()));
    cadAttr.add(new BaseElement("CreatedBy").addText(epmDocument.getCreatorFullName()));
    cadAttr.add(new BaseElement("UpdatedBy").addText(epmDocument.getModifierFullName()));
    cadAttr.add(
        new BaseElement("CreatedTime")
            .addText(
                dateFormat.format(
                    new Date(PersistenceHelper.getCreateStamp(epmDocument).getTime()))));
    cadAttr.add(
        new BaseElement("LastUpdated")
            .addText(
                dateFormat.format(
                    new Date(PersistenceHelper.getModifyStamp(epmDocument).getTime()))));

    cadDocument.add(cadAttr);

    Element docContent = new BaseElement("DocContent");
    if (applicationdataPrimary != null) {
      File file = new File(fileLocation + "/CONTENTS/");
      if (!file.exists()) file.mkdirs();
      ContentServerHelper.service.writeContentStream(
          applicationdataPrimary,
          fileLocation + "/CONTENTS/" + applicationdataPrimary.getFileName());

      docContent.add(
          new BaseElement("ContentPath")
              .addText("CONTENTS/" + applicationdataPrimary.getFileName()));
      docContent.add(
          new BaseElement("ContentFileName").addText(applicationdataPrimary.getFileName()));
      docContent.add(new BaseElement("ContentType").addText("ApplicationData"));
      docContent.add(new BaseElement("ContentType").addText(contentHolder.getRole().toString()));
    }

    cadDocument.add(docContent);
    ;
    return cadDocument;
  }
Example #2
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;
  }