package org.pdxfinder.graph.dao;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.gson.Gson;
import com.fasterxml.jackson.core.type.TypeReference;
import org.apache.commons.lang3.StringUtils;
import org.neo4j.ogm.annotation.NodeEntity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

/**
 * Created by csaba on 25/04/2017.
 */
@NodeEntity
public class MarkerAssociation {

    @Id
    @GeneratedValue
    private Long id;
    private String molecularDataString;
    private List<MolecularData> molecularDataList = new ArrayList<>();

    public MarkerAssociation() {
        molecularDataList = new ArrayList<>();
    }

    public List<MolecularData> decodeMolecularData() throws IOException {
        if (StringUtils.isEmpty(molecularDataString))
            return Collections.emptyList();
        else return new ObjectMapper().readValue(
                molecularDataString,
                new TypeReference<List<MolecularData>>(){});
    }

    public void encodeMolecularData(){
        molecularDataString = new Gson().toJson(molecularDataList);
        molecularDataList = Collections.emptyList();
    }

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public String getMolecularDataString() {
        return molecularDataString;
    }

    public void setMolecularDataString(String molecularDataString) {
        this.molecularDataString = molecularDataString;
    }

    public List<MolecularData> getMolecularDataList() {
        return molecularDataList;
    }

    public void setMolecularDataList(List<MolecularData> molecularDataList) {
        this.molecularDataList = molecularDataList;
    }

    public void addMolecularData(MolecularData md){
        this.molecularDataList.add(md);
    }
}

@@ -605,24 +605,57 @@
 DataString;%0A
+    private int dataPoints = 0;%0A%0A
     private 
@@ -713,16 +713,16 @@
 st%3C%3E();%0A
-
 %0A    pub
@@ -1235,16 +1235,63 @@
 aList);%0A
+        dataPoints = molecularDataList.size();%0A
         
@@ -1962,16 +1962,16 @@
 ta md)%7B%0A
-
         
@@ -2007,11 +2007,171 @@
 );%0A    %7D
+%0A%0A    public int getDataPoints() %7B%0A        return dataPoints;%0A    %7D%0A%0A    public void setDataPoints(int dataPoints) %7B%0A        this.dataPoints = dataPoints;%0A    %7D
 %0A%7D%0A

Store datapoints on MA