コード例 #1
0
  public static void main(String[] args) {
    Mapper mapper = DozerBeanMapperSingletonWrapper.getInstance();
    GetOperatingInstructions operatingInstructions = new GetOperatingInstructions();
    try {
      mapper.map(getOperatingInstructionsData(), operatingInstructions);
    } catch (Exception e) {
      System.out.println(e);
    }

    System.out.println(operatingInstructions);
  }
コード例 #2
0
  @GET
  public Response getPostazioni() {

    logger.debug("getPostazioni called!");

    // Execute query.
    //
    PostazioneService ps = ServiceFactory.createPostazioneService();
    QueryResult<Postazione> result = ps.listPostazioni(null, null, null, null, null);

    // Set up response.
    //
    Mapper mapper = DozerBeanMapperSingletonWrapper.getInstance();
    PostazioniDTO dto = mapper.map(result, PostazioniDTO.class);

    return Response.ok().entity(dto).build();
  }
コード例 #3
0
  @Test
  public final void testRoundtripMapping() {
    try {
      if (inputElement == null) {
        unmarshalInput();
      }
      Mapper mapper = DozerBeanMapperSingletonWrapper.getInstance();
      com.wwidesigner.note.Tuning domainTuning =
          mapper.map(inputElement, com.wwidesigner.note.Tuning.class);
      Tuning bindTuning = mapper.map(domainTuning, Tuning.class);

      outputFile = new File(writePath + "mapperTest.xml");
      outputFile.delete();
      bindFactory.marshalToXml(bindTuning, outputFile);
      XmlDiff diff = new XmlDiff(inputFile, outputFile);
      DetailedDiff detailedDiff = new DetailedDiff(diff);
      assertTrue(detailedDiff.toString(), detailedDiff.identical());
    } catch (Exception e) {
      fail(e.getMessage());
    }
  }
コード例 #4
0
ファイル: BeanUtils.java プロジェクト: lxy545480918/myframe
public class BeanUtils {
  private static final Mapper dozer = DozerBeanMapperSingletonWrapper.getInstance();

  public static <T> T map(Object source, Class<T> destinationClass) {
    return dozer.map(source, destinationClass);
  }

  @SuppressWarnings("unchecked")
  public static <T> T map(Object source, Object dest) {
    dozer.map(source, dest);
    return (T) dest;
  }

  public static void copy(Object source, Object dest) {
    dozer.map(source, dest);
  }

  public static Object getProperty(Object bean, String nm) {
    Object val = null;
    val = MVEL.getProperty(nm, bean);
    return val;
  }

  public static <T> T getProperty(Object bean, String nm, Class<T> type) {
    Object val = getProperty(bean, nm);
    return ConversionUtils.convert(val, type);
  }

  public static void setProperty(Object bean, String nm, Object v) {
    MVEL.setProperty(bean, nm, v);
  }

  public static void setPropertyInMap(Object bean, String nm, Object v) throws Exception {
    Map<String, Object> vars = new HashMap<String, Object>();
    vars.put("key", nm);
    vars.put("value", v);
    MVEL.eval("setProperty(key,value)", bean, vars);
  }
}
コード例 #5
0
/** @author Taylor LABEJOF */
public class InstanceBodyWriterTools {

  private static final Logger LOGGER = Logger.getLogger(InstanceBodyWriterTools.class.getName());
  private static Mapper mapper = DozerBeanMapperSingletonWrapper.getInstance();

  public static void generateInstanceStreamWithGlobalMatrix(
      IProductManagerLocal productService,
      List<PartLink> currentPath,
      Matrix4d matrix,
      InstanceCollection instanceCollection,
      List<Integer> instanceIds,
      JsonGenerator jg) {

    try {

      if (currentPath == null) {
        PartLink rootPartUsageLink =
            productService.getRootPartUsageLink(instanceCollection.getCiKey());
        currentPath = new ArrayList<>();
        currentPath.add(rootPartUsageLink);
      }

      Component component =
          productService.filterProductStructure(
              instanceCollection.getCiKey(), instanceCollection.getFilter(), currentPath, 1);

      PartLink partLink = component.getPartLink();
      PartIteration partI = component.getRetainedIteration();

      // Filter ACL on part
      if (!productService.canAccess(partI.getPartRevision().getKey())) {
        return;
      }

      for (CADInstance instance : partLink.getCadInstances()) {

        List<Integer> copyInstanceIds = new ArrayList<>(instanceIds);
        copyInstanceIds.add(instance.getId());

        Vector3d instanceTranslation =
            new Vector3d(instance.getTx(), instance.getTy(), instance.getTz());
        Vector3d instanceRotation =
            new Vector3d(instance.getRx(), instance.getRy(), instance.getRz());
        Matrix4d combinedMatrix =
            combineTransformation(matrix, instanceTranslation, instanceRotation);

        if (!partI.isAssembly()
            && !partI.getGeometries().isEmpty()
            && instanceCollection.isFiltered(currentPath)) {
          writeLeaf(currentPath, copyInstanceIds, partI, combinedMatrix, jg);
        } else {
          for (Component subComponent : component.getComponents()) {
            generateInstanceStreamWithGlobalMatrix(
                productService,
                subComponent.getPath(),
                combinedMatrix,
                instanceCollection,
                copyInstanceIds,
                jg);
          }
        }
      }

    } catch (PartMasterNotFoundException
        | PartRevisionNotFoundException
        | PartUsageLinkNotFoundException
        | UserNotFoundException
        | WorkspaceNotFoundException
        | ConfigurationItemNotFoundException e) {
      LOGGER.log(Level.SEVERE, null, e);
    } catch (AccessRightException
        | EntityConstraintException
        | NotAllowedException
        | UserNotActiveException e) {
      LOGGER.log(Level.FINEST, null, e);
    }
  }

  public static void generateInstanceStreamWithGlobalMatrix(
      IProductManagerLocal productService,
      List<PartLink> currentPath,
      Matrix4d matrix,
      VirtualInstanceCollection virtualInstanceCollection,
      List<Integer> instanceIds,
      JsonGenerator jg) {
    try {

      PartLink partLink = currentPath.get(currentPath.size() - 1);
      PSFilter filter = virtualInstanceCollection.getFilter();
      List<PartIteration> filteredPartIterations = filter.filter(partLink.getComponent());

      if (!filteredPartIterations.isEmpty()) {

        PartIteration partI = filteredPartIterations.iterator().next();

        // Filter ACL on part
        if (!productService.canAccess(partI.getPartRevision().getKey())) {
          return;
        }

        for (CADInstance instance : partLink.getCadInstances()) {

          List<Integer> copyInstanceIds = new ArrayList<>(instanceIds);
          copyInstanceIds.add(instance.getId());

          Vector3d instanceTranslation =
              new Vector3d(instance.getTx(), instance.getTy(), instance.getTz());
          Vector3d instanceRotation =
              new Vector3d(instance.getRx(), instance.getRy(), instance.getRz());
          Matrix4d combinedMatrix =
              combineTransformation(matrix, instanceTranslation, instanceRotation);

          if (!partI.isAssembly() && !partI.getGeometries().isEmpty()) {
            writeLeaf(currentPath, copyInstanceIds, partI, combinedMatrix, jg);
          } else {
            for (PartLink subLink : partI.getComponents()) {
              List<PartLink> subPath = new ArrayList<>(currentPath);
              subPath.add(subLink);
              generateInstanceStreamWithGlobalMatrix(
                  productService,
                  subPath,
                  combinedMatrix,
                  virtualInstanceCollection,
                  copyInstanceIds,
                  jg);
            }
          }
        }
      }

    } catch (UserNotFoundException
        | UserNotActiveException
        | WorkspaceNotFoundException
        | PartRevisionNotFoundException e) {
      e.printStackTrace();
    }
  }

  private static Matrix4d combineTransformation(
      Matrix4d matrix, Vector3d translation, Vector3d rotation) {
    Matrix4d gM = new Matrix4d(matrix);
    Matrix4d m = new Matrix4d();

    m.setIdentity();
    m.setTranslation(translation);
    gM.mul(m);

    m.setIdentity();
    m.rotZ(rotation.z);
    gM.mul(m);

    m.setIdentity();
    m.rotY(rotation.y);
    gM.mul(m);

    m.setIdentity();
    m.rotX(rotation.x);
    gM.mul(m);

    return gM;
  }

  private static void writeLeaf(
      List<PartLink> currentPath,
      List<Integer> copyInstanceIds,
      PartIteration partI,
      Matrix4d combinedMatrix,
      JsonGenerator jg) {
    String partIterationId = partI.toString();
    List<InstanceAttributeDTO> attributes = new ArrayList<>();
    for (InstanceAttribute attr : partI.getInstanceAttributes()) {
      attributes.add(mapper.map(attr, InstanceAttributeDTO.class));
    }

    jg.writeStartObject();
    jg.write("id", Tools.getPathInstanceAsString(currentPath, copyInstanceIds));
    jg.write("partIterationId", partIterationId);
    jg.write("path", Tools.getPathAsString(currentPath));

    writeMatrix(combinedMatrix, jg);
    writeGeometries(partI.getSortedGeometries(), jg);
    writeAttributes(attributes, jg);

    jg.writeEnd();
    jg.flush();
  }

  private static void writeMatrix(Matrix4d matrix, JsonGenerator jg) {
    jg.writeStartArray("matrix");
    for (int i = 0; i < 4; i++) {
      for (int j = 0; j < 4; j++) {
        jg.write(matrix.getElement(i, j));
      }
    }
    jg.writeEnd();
  }

  private static void writeGeometries(List<Geometry> files, JsonGenerator jg) {
    jg.write("qualities", files.size());

    if (!files.isEmpty()) {
      Geometry geometry = files.get(0);
      jg.write("xMin", geometry.getxMin());
      jg.write("yMin", geometry.getyMin());
      jg.write("zMin", geometry.getzMin());
      jg.write("xMax", geometry.getxMax());
      jg.write("yMax", geometry.getyMax());
      jg.write("zMax", geometry.getzMax());
    }

    jg.writeStartArray("files");

    for (Geometry g : files) {
      jg.writeStartObject();
      jg.write("fullName", "api/files/" + g.getFullName());
      jg.writeEnd();
    }
    jg.writeEnd();
  }

  private static void writeAttributes(List<InstanceAttributeDTO> attributes, JsonGenerator jg) {
    jg.writeStartArray("attributes");
    for (InstanceAttributeDTO a : attributes) {
      jg.writeStartObject();
      jg.write("name", a.getName());
      jg.write("type", a.getType().toString());
      jg.write("value", a.getValue());
      jg.writeEnd();
    }
    jg.writeEnd();
  }
}