Commit 51dfe812 authored by Shirley Crompton's avatar Shirley Crompton
Browse files

attempt to fix null pointer exception for simple deployment

parent c14ec070
...@@ -116,8 +116,9 @@ public class Mapper { ...@@ -116,8 +116,9 @@ public class Mapper {
//to hold the metricVariableValues //to hold the metricVariableValues
// go ahead // go ahead
List<MetricVariable> mvs = cp.getMetricVariables(); List<MetricVariable> mvs = cp.getMetricVariables();
log.debug("...about to get metric variables....");
// //
if (mvs.isEmpty()) { if (mvs == null || mvs.isEmpty()) {
log.debug("CP model in " + resId log.debug("CP model in " + resId
+ " has no Metric Variable entities..."); + " has no Metric Variable entities...");
} else { } else {
...@@ -139,6 +140,8 @@ public class Mapper { ...@@ -139,6 +140,8 @@ public class Mapper {
solution = CpModelTool.setConstantValue(mv, solution); solution = CpModelTool.setConstantValue(mv, solution);
} }
} else {// cp generator has created the solution } else {// cp generator has created the solution
log.debug("CP model in " + resId
+ " already has a Solution entity...");
// match the metricVariables // match the metricVariables
for (MetricVariable mv : mvs) { for (MetricVariable mv : mvs) {
if (CPModelTool.searchMetricValue(solution, mv) == null) { if (CPModelTool.searchMetricValue(solution, mv) == null) {
...@@ -151,11 +154,15 @@ public class Mapper { ...@@ -151,11 +154,15 @@ public class Mapper {
jObj.add("solution_tmp", solution.getTimestamp()); // milp-solver needs this jObj.add("solution_tmp", solution.getTimestamp()); // milp-solver needs this
} }
if (updateCP) { if (updateCP) {
log.debug("updating CP Model( " + resId
+ ") in CDO...");
//get a new resource id //get a new resource id
String newId = CpModelTool.getCloneId(CpModelTool.getAppId(model_contents), resId); String newId = CpModelTool.getCloneId(CpModelTool.getAppId(model_contents), resId);
this.utils.overwriteCPModelinCDO(model_contents, newId); this.utils.overwriteCPModelinCDO(model_contents, newId);
jObj.add("id", newId); jObj.add("id", newId);
}else{ }else{
log.debug("no change to CP Model(" + resId
+ ") ...");
//we are using the same model //we are using the same model
jObj.add("id", resId); jObj.add("id", resId);
} }
...@@ -254,6 +261,9 @@ public class Mapper { ...@@ -254,6 +261,9 @@ public class Mapper {
} }
//ready to save to CDO, get a new resource id //ready to save to CDO, get a new resource id
String newId = CpModelTool.getCloneId(CpModelTool.getAppId(model_contents), resId); String newId = CpModelTool.getCloneId(CpModelTool.getAppId(model_contents), resId);
//debug
//System.out.println("I am here ... ");
//this.utils.overwriteCPModelinCDO(model_contents, newId);
this.utils.overwriteCPModelinCDO(model_contents, newId); this.utils.overwriteCPModelinCDO(model_contents, newId);
jObj.add("id", newId); jObj.add("id", newId);
// explicitly stop the cdo client // explicitly stop the cdo client
......
...@@ -183,6 +183,7 @@ public final class CdoTool { ...@@ -183,6 +183,7 @@ public final class CdoTool {
EList<EObject> contents1 = cdo.getContents(); EList<EObject> contents1 = cdo.getContents();
try{ try{
if(contents1.size() > 0){ if(contents1.size() > 0){
log.debug(" ... there are contents, will be deleting.....");
//do this via CDO id //do this via CDO id
CDOObject cdoObj = (CDOObject) contents1.get(0); CDOObject cdoObj = (CDOObject) contents1.get(0);
trans.getObject(cdoObj.cdoID()); trans.getObject(cdoObj.cdoID());
......
...@@ -236,6 +236,7 @@ public final class CpModelTool { ...@@ -236,6 +236,7 @@ public final class CpModelTool {
try { try {
for (EObject obj : model) { for (EObject obj : model) {
if (obj instanceof eu.paasage.upperware.metamodel.cp.impl.ConstraintProblemImpl) { if (obj instanceof eu.paasage.upperware.metamodel.cp.impl.ConstraintProblemImpl) {
log.debug("found constraint problem....");
cpModel = (ConstraintProblem) obj; cpModel = (ConstraintProblem) obj;
break; break;
} }
...@@ -281,10 +282,11 @@ public final class CpModelTool { ...@@ -281,10 +282,11 @@ public final class CpModelTool {
for(int i = suffix.length()-1; i >=0; i--){ for(int i = suffix.length()-1; i >=0; i--){
char character = suffix.charAt(i); char character = suffix.charAt(i);
log.debug("suffix char at " + i + " is " + suffix.charAt(i)); log.debug("suffix char at " + i + " is " + suffix.charAt(i));
if(Character.isLetter(character)){ if(Character.isLetter(character) || character == '_'){
//stop here //stop here
log.debug("The numeric part of the suffix is : " + suffix.substring(i+1)); log.debug("The numeric part of the suffix is : " + suffix.substring(i+1));
int version = Integer.parseInt(suffix.substring(i+1))+1; int version = Integer.parseInt(suffix.substring(i+1))+1;
log.debug("the version is : " + version);
cloneId = appId + suffix.substring(0, i+1) + version; cloneId = appId + suffix.substring(0, i+1) + version;
log.debug("the computed cloneId is " + cloneId); log.debug("the computed cloneId is " + cloneId);
break; break;
......
...@@ -243,4 +243,10 @@ public class CpModelToolTest { ...@@ -243,4 +243,10 @@ public class CpModelToolTest {
} }
assertTrue("Failed to add the metric variable",found); assertTrue("Failed to add the metric variable",found);
} }
@Test
public void testIGetCloneId(){
String cloneId = CpModelTool.getCloneId("upperware-models/OpenFoamApplication1447777579963", "upperware-models/OpenFoamApplication1447777579963_2");
assertEquals("Error getting cloned id, got : " + cloneId, "upperware-models/OpenFoamApplication1447777579963_3", cloneId );
}
} }
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment