Search in sources :

Example 1 with DataNodeDto

use of org.pentaho.platform.api.repository2.unified.webservices.DataNodeDto in project pentaho-platform by pentaho.

the class NodeRepositoryFileDataAdapter method toDataNodeDto.

protected void toDataNodeDto(final DataNodeDto nodeDto, final DataNode node) {
    nodeDto.setName(node.getName());
    if (node.getId() != null) {
        nodeDto.setId(node.getId().toString());
    }
    List<DataPropertyDto> dtoProps = new ArrayList<DataPropertyDto>();
    for (DataProperty prop : node.getProperties()) {
        DataPropertyDto dtoProp = new DataPropertyDto();
        dtoProp.setName(prop.getName());
        if ((prop.getType() == DataPropertyType.BOOLEAN) || (prop.getType() == DataPropertyType.DOUBLE) || (prop.getType() == DataPropertyType.LONG) || (prop.getType() == DataPropertyType.STRING) || (prop.getType() == DataPropertyType.REF)) {
            dtoProp.setValue(prop.getString());
        } else if (prop.getType() == DataPropertyType.DATE) {
            Date dateProp = prop.getDate();
            dtoProp.setValue(dateProp != null ? String.valueOf(dateProp.getTime()) : null);
        } else {
            throw new IllegalArgumentException();
        }
        dtoProp.setType(prop.getType() != null ? prop.getType().ordinal() : -1);
        dtoProps.add(dtoProp);
    }
    nodeDto.setChildProperties(dtoProps);
    List<DataNodeDto> nodeDtos = new ArrayList<DataNodeDto>();
    for (DataNode childNode : node.getNodes()) {
        DataNodeDto child = new DataNodeDto();
        nodeDtos.add(child);
        toDataNodeDto(child, childNode);
    }
    nodeDto.setChildNodes(nodeDtos);
}
Also used : DataPropertyDto(org.pentaho.platform.api.repository2.unified.webservices.DataPropertyDto) DataNodeDto(org.pentaho.platform.api.repository2.unified.webservices.DataNodeDto) DataNode(org.pentaho.platform.api.repository2.unified.data.node.DataNode) ArrayList(java.util.ArrayList) DataProperty(org.pentaho.platform.api.repository2.unified.data.node.DataProperty) Date(java.util.Date)

Example 2 with DataNodeDto

use of org.pentaho.platform.api.repository2.unified.webservices.DataNodeDto in project pentaho-platform by pentaho.

the class NodeRepositoryFileDataAdapter method toDataNode.

protected DataNode toDataNode(final DataNodeDto nodeDto) {
    DataNode node = new DataNode(nodeDto.getName());
    node.setId(nodeDto.getId());
    for (DataPropertyDto dtoProp : nodeDto.getChildProperties()) {
        int type = dtoProp.getType();
        String name = dtoProp.getName();
        String value = dtoProp.getValue();
        if (type == DataPropertyType.BOOLEAN.ordinal()) {
            node.setProperty(name, Boolean.parseBoolean(value));
        } else if (type == DataPropertyType.DATE.ordinal()) {
            node.setProperty(name, new Date(Long.parseLong(value)));
        } else if (type == DataPropertyType.DOUBLE.ordinal()) {
            node.setProperty(name, Double.parseDouble(value));
        } else if (type == DataPropertyType.LONG.ordinal()) {
            node.setProperty(name, Long.parseLong(value));
        } else if (type == DataPropertyType.STRING.ordinal()) {
            node.setProperty(name, value);
        } else if (type == DataPropertyType.REF.ordinal()) {
            node.setProperty(name, new DataNodeRef(value));
        } else {
            throw new IllegalArgumentException();
        }
    }
    for (DataNodeDto childNodeDto : nodeDto.getChildNodes()) {
        node.addNode(toDataNode(childNodeDto));
    }
    return node;
}
Also used : DataNodeRef(org.pentaho.platform.api.repository2.unified.data.node.DataNodeRef) DataPropertyDto(org.pentaho.platform.api.repository2.unified.webservices.DataPropertyDto) DataNodeDto(org.pentaho.platform.api.repository2.unified.webservices.DataNodeDto) DataNode(org.pentaho.platform.api.repository2.unified.data.node.DataNode) Date(java.util.Date)

Example 3 with DataNodeDto

use of org.pentaho.platform.api.repository2.unified.webservices.DataNodeDto in project pentaho-platform by pentaho.

the class NodeRepositoryFileDataAdapter method marshal.

@Override
public NodeRepositoryFileDataDto marshal(final NodeRepositoryFileData v) {
    NodeRepositoryFileDataDto d = new NodeRepositoryFileDataDto();
    DataNodeDto node = new DataNodeDto();
    d.setNode(node);
    toDataNodeDto(node, v.getNode());
    return d;
}
Also used : NodeRepositoryFileDataDto(org.pentaho.platform.api.repository2.unified.webservices.NodeRepositoryFileDataDto) DataNodeDto(org.pentaho.platform.api.repository2.unified.webservices.DataNodeDto)

Aggregations

DataNodeDto (org.pentaho.platform.api.repository2.unified.webservices.DataNodeDto)3 Date (java.util.Date)2 DataNode (org.pentaho.platform.api.repository2.unified.data.node.DataNode)2 DataPropertyDto (org.pentaho.platform.api.repository2.unified.webservices.DataPropertyDto)2 ArrayList (java.util.ArrayList)1 DataNodeRef (org.pentaho.platform.api.repository2.unified.data.node.DataNodeRef)1 DataProperty (org.pentaho.platform.api.repository2.unified.data.node.DataProperty)1 NodeRepositoryFileDataDto (org.pentaho.platform.api.repository2.unified.webservices.NodeRepositoryFileDataDto)1