diff --git a/src/main/java/no/nibio/vips/logic/scheduling/model/preprocessor/PhenologyModelPreprocessor.java b/src/main/java/no/nibio/vips/logic/scheduling/model/preprocessor/PhenologyModelPreprocessor.java index 1153548cbd45163bb511f41d2db438c6c3b415bc..c31b206a273daf4fc49c6dea5237ad3a17ce2883 100644 --- a/src/main/java/no/nibio/vips/logic/scheduling/model/preprocessor/PhenologyModelPreprocessor.java +++ b/src/main/java/no/nibio/vips/logic/scheduling/model/preprocessor/PhenologyModelPreprocessor.java @@ -159,11 +159,31 @@ public class PhenologyModelPreprocessor extends ModelRunPreprocessor{ Plant plantDBData = getConfigurationPlantation(FILE_PLANTATION); + if(!plantDBData.getTypeNames().isEmpty()) + { + for(Plantation objTypeNames: plantDBData.getTypeNames()) + { + if(objTypeNames.getTypeName().equals((paramPhenologyTypeName))) + { + + plant.setSpeciesLatinName(plantDBData.getSpeciesLatinName()); + plant.setBaseTemp(objTypeNames.getBaseTemp()); + List<Plantation> typeNames = new ArrayList<Plantation>(); + typeNames.add(objTypeNames); + plant.setTypeNames(typeNames); + plant.setStartDate(paramSowingDate); + break; + } + } + } + + /* if(plantDBData.getTypeName().equals(paramPhenologyTypeName)) { plant = plantDBData; plant.setStartDate(paramSowingDate); } + */ //plant.setTypeName(paramPhenologyTypeName); //plant.setStartDate(paramSowingDate); @@ -319,8 +339,42 @@ public class PhenologyModelPreprocessor extends ModelRunPreprocessor{ JsonFactory f = new MappingJsonFactory(); JsonParser jp = f.createParser(inputStream); JsonNode all = jp.readValueAsTree(); - JsonNode nodePhaseInfo = all.path("phaseInfo"); + JsonNode nodeTypeNames = all.path("typeNames"); + if(nodeTypeNames.isArray()) + { + for(JsonNode nodeTypeName : nodeTypeNames) + { + Plantation plantation = new Plantation(); + plantation.setTypeName(nodeTypeName.get("typeName").asText()); + if(null != nodeTypeName.get("baseTemp").asText()) + { + plantation.setBaseTemp(nodeTypeName.get("baseTemp").asDouble()); + } + JsonNode nodeAllPhaseInfo = nodeTypeName.path("phaseInfo"); + if(nodeAllPhaseInfo.isArray()) + { + List<Plantation.PhaseInfo> listPhaseInfo = new ArrayList<Plantation.PhaseInfo>(); + for(JsonNode nodePhaseInfo : nodeAllPhaseInfo) + { + Plantation.PhaseInfo phaseInfo = new Plantation().new PhaseInfo(); + phaseInfo.setPhaseName(nodePhaseInfo.get("phaseName").asText()); + phaseInfo.setHeatReq(nodePhaseInfo.get("heatReq").asDouble()); + listPhaseInfo.add(phaseInfo); + } + if(listPhaseInfo.size() != 0) + { + plantation.setPhaseInfo(listPhaseInfo); + } + } + plantations.add(plantation); + } + + } + + + /* + JsonNode nodePhaseInfo = all.path("phaseInfo"); plant.setSpeciesLatinName(all.get("speciesLatinName").asText()); plant.setTypeName(all.get("typeName").asText()); plant.setBaseTemp(all.get("baseTemp").asDouble()); @@ -337,8 +391,8 @@ public class PhenologyModelPreprocessor extends ModelRunPreprocessor{ plantations.add(plantation); } } - - plant.setPlantations(plantations); + */ + plant.setTypeNames(plantations); } catch (IOException ex) { diff --git a/src/main/java/no/nibio/vips/logic/util/Plant.java b/src/main/java/no/nibio/vips/logic/util/Plant.java index 780e67e49ef173ee65a1f9d3e92eb18ca12caee2..ce4230d8e2aea178401bbad7eef752b13d5ddeaa 100644 --- a/src/main/java/no/nibio/vips/logic/util/Plant.java +++ b/src/main/java/no/nibio/vips/logic/util/Plant.java @@ -11,50 +11,38 @@ import java.util.List; public class Plant { private String speciesLatinName; - private String typeName; private Double baseTemp; private Date startDate; - - private List<Plantation> plantations; + private List<Plantation> typeNames; public String getSpeciesLatinName() { return speciesLatinName; } - public void setSpeciesLatinName(String speciesLatinName) { this.speciesLatinName = speciesLatinName; } - - public String getTypeName() { - return typeName; - } - - public void setTypeName(String typeName) { - this.typeName = typeName; - } - public Double getBaseTemp() { return baseTemp; } - public void setBaseTemp(Double baseTemp) { this.baseTemp = baseTemp; } - public Date getStartDate() { return startDate; } - public void setStartDate(Date startDate) { this.startDate = startDate; } - - public List<Plantation> getPlantations() { - return plantations; + public List<Plantation> getTypeNames() { + return typeNames; + } + public void setTypeNames(List<Plantation> typeNames) { + this.typeNames = typeNames; } - public void setPlantations(List<Plantation> plantations) { - this.plantations = plantations; + @Override + public String toString() { + return "Plant{" + "speciesLatinName=" + speciesLatinName + ", baseTemp=" + baseTemp + ", startDate=" + startDate + ", typeNames=" + typeNames + '}'; } - + } diff --git a/src/main/java/no/nibio/vips/logic/util/Plantation.java b/src/main/java/no/nibio/vips/logic/util/Plantation.java index 42fd0febb1d13e22f21840fd90eb1b85f16eb2e7..09448b191d8ca26dc8e31e94f09ffc71bd3c3a62 100644 --- a/src/main/java/no/nibio/vips/logic/util/Plantation.java +++ b/src/main/java/no/nibio/vips/logic/util/Plantation.java @@ -2,6 +2,7 @@ package no.nibio.vips.logic.util; import java.util.Date; +import java.util.List; /** * @@ -11,25 +12,23 @@ import java.util.Date; public class Plantation { private String typeName; - private String phaseName; - //private String baseTemp; - private Double heatReq; - //private Date startDate; - + private Double baseTemp; + List<PhaseInfo> phaseInfo; + public Plantation() { } - public Plantation(String typeName, String phaseName, Double heatReq) { - this.typeName = typeName; - this.phaseName = phaseName; - this.heatReq = heatReq; + public Plantation(String typeName, List<PhaseInfo> phaseInfo) { + this.typeName = typeName; + this.phaseInfo = phaseInfo; } - public Plantation(String phaseName, Double heatReq) { - this.phaseName = phaseName; - this.heatReq = heatReq; + public Plantation(String typeName,Double baseTemp, List<PhaseInfo> phaseInfo) { + this.typeName = typeName; + this.baseTemp = baseTemp; + this.phaseInfo = phaseInfo; } - + public String getTypeName() { return typeName; } @@ -38,25 +37,56 @@ public class Plantation { this.typeName = typeName; } - public String getPhaseName() { - return phaseName; + public Double getBaseTemp() { + return baseTemp; } - public void setPhaseName(String phaseName) { - this.phaseName = phaseName; + public void setBaseTemp(Double baseTemp) { + this.baseTemp = baseTemp; } - public Double getHeatReq() { - return heatReq; + public List<PhaseInfo> getPhaseInfo() { + return phaseInfo; } - public void setHeatReq(Double heatReq) { - this.heatReq = heatReq; + public void setPhaseInfo(List<PhaseInfo> phaseInfo) { + this.phaseInfo = phaseInfo; } + @Override public String toString() { - return "Plantation{" + "typeName=" + typeName + ", phaseName=" + phaseName + ", heatReq=" + heatReq + '}'; + return "Plantation{" + "typeName=" + typeName + ", baseTemp=" + baseTemp + ", phaseInfo=" + phaseInfo + '}'; } + + public class PhaseInfo + { + private String phaseName; + private Double heatReq; + + public String getPhaseName() { + return phaseName; + } + public void setPhaseName(String phaseName) { + this.phaseName = phaseName; + } + + public Double getHeatReq() { + return heatReq; + } + + public void setHeatReq(Double heatReq) { + this.heatReq = heatReq; + } + + @Override + public String toString() { + return "PhaseInfo{" + "phaseName=" + phaseName + ", heatReq=" + heatReq + '}'; + } + + } + + } + diff --git a/src/main/resources/dataset/plantationData.json b/src/main/resources/dataset/plantationData.json index 5e041fff133df829ff603343effcdb9053f90c0c..f23f3078a6e5df11cb0ce33a58e286ab69aa8aae 100644 --- a/src/main/resources/dataset/plantationData.json +++ b/src/main/resources/dataset/plantationData.json @@ -1,49 +1,56 @@ { "speciesLatinName" : "Zea mays", - "typeName" : "TESTVARIETY 2", "baseTemp" : "10", - "phaseInfo": -[ - { - "phaseName": "VE", - "heatReq" : "66.67" - }, - { - "phaseName": "V2", - "heatReq" : "111.11" - }, - { - "phaseName": "V3", - "heatReq" : "194.44" - }, - { - "phaseName": "V4-V6", - "heatReq" : "263.89" - }, - { - "phaseName": "V7-V9", - "heatReq" : "338.89" - }, - { - "phaseName": "V10", - "heatReq" : "411.11" - }, - { - "phaseName": "VT", - "heatReq" : "630.55" - }, - { - "phaseName": "R2", - "heatReq" : "922.22" - }, - { - "phaseName": "R5", - "heatReq" : "1361.11" - }, - { - "phaseName": "R6", - "heatReq" : "1500" - } - -] + "typeNames" : + [ + { + "typeName" : "TESTVARIETY 2", + "baseTemp" : "10", + "phaseInfo": + [ + { + "phaseName": "VE", + "heatReq" : "66.67" + }, + { + "phaseName": "V2", + "heatReq" : "111.11" + }, + { + "phaseName": "V3", + "heatReq" : "194.44" + }, + { + "phaseName": "V4-V6", + "heatReq" : "263.89" + }, + { + "phaseName": "V7-V9", + "heatReq" : "338.89" + }, + { + "phaseName": "V10", + "heatReq" : "411.11" + }, + { + "phaseName": "VT", + "heatReq" : "630.55" + }, + { + "phaseName": "R2", + "heatReq" : "922.22" + }, + { + "phaseName": "R5", + "heatReq" : "1361.11" + }, + { + "phaseName": "R6", + "heatReq" : "1500" + } + + ] + } + ] + } \ No newline at end of file