@Override
  public void populate(final SOURCE source, final TARGET target) {
    Assert.notNull(source, "Parameter source cannot be null.");
    Assert.notNull(target, "Parameter target cannot be null.");

    target.setCode(source.getCode());
    target.setName(source.getName());
    target.setDescription(source.getDescription());
  }
Ejemplo n.º 2
0
  private void writeJmsBridge(XMLExtendedStreamWriter writer, String bridgeName, ModelNode value)
      throws XMLStreamException {
    writer.writeStartElement(Element.JMS_BRIDGE.getLocalName());

    if (!DEFAULT.equals(bridgeName)) {
      writer.writeAttribute(Attribute.NAME.getLocalName(), bridgeName);
    }

    JMSBridgeDefinition.MODULE.marshallAsAttribute(value, writer);

    writer.writeStartElement(SOURCE.getLocalName());
    for (AttributeDefinition attr : JMSBridgeDefinition.JMS_SOURCE_ATTRIBUTES) {
      attr.marshallAsElement(value, writer);
    }
    writer.writeEndElement();

    writer.writeStartElement(TARGET.getLocalName());
    for (AttributeDefinition attr : JMSBridgeDefinition.JMS_TARGET_ATTRIBUTES) {
      attr.marshallAsElement(value, writer);
    }
    writer.writeEndElement();

    for (AttributeDefinition attr : JMSBridgeDefinition.JMS_BRIDGE_ATTRIBUTES) {
      if (attr == JMSBridgeDefinition.MODULE) {
        // handled as a XML attribute
        continue;
      }
      attr.marshallAsElement(value, writer);
    }

    writer.writeEndElement();
  }
  @Override
  public void populate(final SOURCE productModel, final TARGET productData)
      throws ConversionException {
    final PriceDataType priceType;
    final PriceInformation info;
    if (CollectionUtils.isEmpty(productModel.getVariants())) {
      priceType = PriceDataType.BUY;
      info = getCommercePriceService().getWebPriceForProduct(productModel);
    } else {
      priceType = PriceDataType.FROM;
      info = getCommercePriceService().getFromPriceForProduct(productModel);
    }

    if (info != null) {
      final PriceData priceData =
          getPriceDataFactory()
              .create(
                  priceType,
                  BigDecimal.valueOf(info.getPriceValue().getValue()),
                  info.getPriceValue().getCurrencyIso());
      productData.setPrice(priceData);
    } else {
      productData.setPurchasable(Boolean.FALSE);
    }
  }
 public static SOURCE findById(int id) {
   for (final SOURCE aSource : SOURCE.values()) {
     if (aSource.id == id) {
       return aSource;
     }
   }
   return null;
 }
  @Override
  public void populate(final SOURCE source, final TARGET target) {
    target.setPagination(source.getPagination());
    target.setSorts(source.getSorts());
    target.setResults(
        Converters.convertAll(source.getResults(), getPointOfServiceDistanceConverter()));

    target.setLocationText(source.getLocationText());
    target.setSourceLatitude(source.getSourceLatitude());
    target.setSourceLongitude(source.getSourceLongitude());
    target.setBoundNorthLatitude(source.getBoundNorthLatitude());
    target.setBoundSouthLatitude(source.getBoundSouthLatitude());
    target.setBoundWestLongitude(source.getBoundWestLongitude());
    target.setBoundEastLongitude(source.getBoundEastLongitude());

    if (target.getResults() != null && !target.getResults().isEmpty()) {
      final String urlPrefix = "/store/";
      final String urlQueryParams = getStoreUrlQueryParams(target);

      for (final PointOfServiceData pointOfService : target.getResults()) {
        pointOfService.setUrl(urlPrefix + pointOfService.getName() + urlQueryParams);
      }
    }
  }
  @Override
  public void serialize(CyNetworkView networkView, JsonGenerator jgen, SerializerProvider provider)
      throws IOException, JsonProcessingException {
    jgen.useDefaultPrettyPrinter();

    jgen.writeStartObject();
    jgen.writeStringField(
        CytoscapeJsNetworkModule.FORMAT_VERSION_TAG, CytoscapeJsNetworkModule.FORMAT_VERSION);
    jgen.writeStringField(CytoscapeJsNetworkModule.GENERATED_BY_TAG, "cytoscape-" + version);
    jgen.writeStringField(
        CytoscapeJsNetworkModule.TARGET_CYJS_VERSION_TAG,
        CytoscapeJsNetworkModule.CYTOSCAPEJS_VERSION);

    final CyNetwork network = networkView.getModel();

    // Serialize network data table
    jgen.writeObjectFieldStart(DATA.getTag());
    jgen.writeObject(network.getRow(network));
    jgen.writeEndObject();

    jgen.writeObjectFieldStart(ELEMENTS.getTag());

    // Write array
    final List<CyNode> nodes = network.getNodeList();
    final List<CyEdge> edges = network.getEdgeList();

    jgen.writeArrayFieldStart(NODES.getTag());
    for (final CyNode node : nodes) {
      jgen.writeStartObject();

      // Data field
      jgen.writeObjectFieldStart(DATA.getTag());
      jgen.writeStringField(ID.getTag(), node.getSUID().toString());
      // Write CyRow in "data" field
      jgen.writeObject(network.getRow(node));
      jgen.writeEndObject();

      // Position and other visual props
      jgen.writeObject(networkView.getNodeView(node));

      // Special case for cytoscape.js format:
      // - Selected
      jgen.writeBooleanField(
          CyNetwork.SELECTED, network.getRow(node).get(CyNetwork.SELECTED, Boolean.class));

      jgen.writeEndObject();
    }
    jgen.writeEndArray();

    jgen.writeArrayFieldStart(EDGES.getTag());
    for (final CyEdge edge : edges) {
      jgen.writeStartObject();

      jgen.writeObjectFieldStart(DATA.getTag());
      jgen.writeStringField(ID.getTag(), edge.getSUID().toString());
      jgen.writeStringField(SOURCE.getTag(), edge.getSource().getSUID().toString());
      jgen.writeStringField(TARGET.getTag(), edge.getTarget().getSUID().toString());

      // Write CyRow in "data" field
      jgen.writeObject(network.getRow(edge));

      jgen.writeEndObject();

      // Special case for cytoscape.js format:
      // - Selected
      jgen.writeBooleanField(
          CyNetwork.SELECTED, network.getRow(edge).get(CyNetwork.SELECTED, Boolean.class));

      jgen.writeEndObject();
    }
    jgen.writeEndArray();

    jgen.writeEndObject();
  }
 protected String retrieveContextName(SOURCE source) {
   return (source != null) ? source.getClass().getName() : this.getClass().getName();
 }