Changeset 5761 for branches/OKBJavaConnector/src/main/java/com/heuristiclab/okb/wsclient/OKBServiceClient.java
- Timestamp:
- 03/19/11 09:37:18 (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/OKBJavaConnector/src/main/java/com/heuristiclab/okb/wsclient/OKBServiceClient.java
r5673 r5761 1 1 package com.heuristiclab.okb.wsclient; 2 2 3 import static at.hl.okb.wsclient.Utilities.createNameFilter;3 //import static at.hl.okb.wsclient.Utilities.createNameFilter; 4 4 5 5 import java.util.HashMap; … … 8 8 import java.util.Set; 9 9 10 import at.hl.wsclient.okb.Algorithm;11 import at.hl.wsclient.okb.AlgorithmClass;12 import at.hl.wsclient.okb.AlgorithmData;13 import at.hl.wsclient.okb.AlgorithmParameter;14 import at.hl.wsclient.okb.ArrayOfAlgorithmParameter;15 import at.hl.wsclient.okb.ArrayOfProblemParameter;16 import at.hl.wsclient.okb.IOKBService;17 import at.hl.wsclient.okb.NamedOKBItem;18 import at.hl.wsclient.okb.OKBService;19 import at.hl.wsclient.okb.ObjectFactory;20 import at.hl.wsclient.okb.Platform;21 import at.hl.wsclient.okb.Problem;22 import at.hl.wsclient.okb.ProblemClass;23 import at.hl.wsclient.okb.ProblemData;24 import at.hl.wsclient.okb.ProblemParameter;10 //import at.hl.wsclient.okb.Algorithm; 11 //import at.hl.wsclient.okb.AlgorithmClass; 12 //import at.hl.wsclient.okb.AlgorithmData; 13 //import at.hl.wsclient.okb.AlgorithmParameter; 14 //import at.hl.wsclient.okb.ArrayOfAlgorithmParameter; 15 //import at.hl.wsclient.okb.ArrayOfProblemParameter; 16 //import at.hl.wsclient.okb.IOKBService; 17 //import at.hl.wsclient.okb.NamedOKBItem; 18 //import at.hl.wsclient.okb.OKBService; 19 //import at.hl.wsclient.okb.ObjectFactory; 20 //import at.hl.wsclient.okb.Platform; 21 //import at.hl.wsclient.okb.Problem; 22 //import at.hl.wsclient.okb.ProblemClass; 23 //import at.hl.wsclient.okb.ProblemData; 24 //import at.hl.wsclient.okb.ProblemParameter; 25 25 26 26 import com.google.common.collect.Iterables; 27 27 28 28 public class OKBServiceClient { 29 OKBService srv = null;30 IOKBService port = null;31 ObjectFactory factory = new ObjectFactory();32 29 33 public OKBServiceClient() {34 this.srv = new OKBService();35 this.port = srv.getWSHttpBindingIOKBService1();36 }37 38 public Long getPlatformId(String platformName) {39 Platform returnValue = Iterables.find(40 port.getPlatforms().getPlatform(),41 createNameFilter(platformName), null);42 43 return returnValue != null ? returnValue.getId() : null;44 }45 46 public Long getProblemId(String problemName) {47 Problem returnValue = Iterables.find(port.getProblems().getProblem(),48 createNameFilter(problemName), null);49 50 return returnValue != null ? returnValue.getId() : null;51 }52 53 public Long getProblemClassId(String problemClass) {54 ProblemClass returnValue = Iterables.find(port.getProblemClasses()55 .getProblemClass(), createNameFilter(problemClass), null);56 57 return returnValue != null ? returnValue.getId() : null;58 59 }60 61 public Long getAlgorithmClassId(String algorithmClassName) {62 AlgorithmClass returnValue = Iterables.find(port.getAlgorithmClasses()63 .getAlgorithmClass(), createNameFilter(algorithmClassName),64 null);65 66 return returnValue != null ? returnValue.getId() : null;67 68 }69 70 public Long getProblem(String problemName, Long problemClassId,71 Long platformId) {72 Problem problem = null;73 Iterator<Problem> it = port.getProblems().getProblem().iterator();74 75 while (it.hasNext() && problem == null) {76 Problem tmpProblem = it.next();77 if (platformId.equals(tmpProblem.getPlatformId())78 && problemName.equals(tmpProblem.getName().getValue())79 && problemClassId.equals(tmpProblem.getProblemClassId())) {80 81 problem = tmpProblem;82 }83 }84 return problem != null ? problem.getId() : null;85 }86 87 public Long getAlgorithmId(String algorithmName, /* Long algorithmClassId, */88 Long platformId) {89 Algorithm algorithm = null;90 91 Iterator<Algorithm> it = port.getAlgorithms().getAlgorithm().iterator();92 93 while (it.hasNext() && algorithm == null) {94 Algorithm tmpAlgo = it.next();95 if (platformId.equals(tmpAlgo.getPlatformId())96 && algorithmName.equals(tmpAlgo.getName().getValue())97 // && algorithmClassId.equals(tmpAlgo.getAlgorithmClassId())98 ) {99 algorithm = tmpAlgo;100 }101 }102 103 return algorithm != null ? algorithm.getId() : null;104 105 }106 107 public Map<String, Object> getAlgorithmParameterMap(Long algorithmId) {108 Map<String, Object> returnMap = new HashMap<String, Object>();109 110 ArrayOfAlgorithmParameter algoParamList = port111 .getAlgorithmParameters(algorithmId);112 113 for (AlgorithmParameter algoParam : algoParamList114 .getAlgorithmParameter()) {115 returnMap.put(algoParam.getName().getValue(), null);116 }117 118 return returnMap;119 }120 121 public Map<String, Object> getProblemParameterMap(Long ProblemId) {122 Map<String, Object> returnMap = new HashMap<String, Object>();123 124 ArrayOfProblemParameter algoParamList = port125 .getProblemParameters(ProblemId);126 127 for (ProblemParameter algoParam : algoParamList128 .getProblemParameter()) {129 returnMap.put(algoParam.getName().getValue(), null);130 }131 132 return returnMap;133 }134 135 136 137 private <T extends NamedOKBItem> T createNamedOKBItem(Class<T> clazz,138 String name) {139 try {140 T instance = clazz.newInstance();141 instance.setName(factory.createNamedOKBItemName(name));142 return instance;143 } catch (IllegalAccessException ex) {144 throw new IllegalArgumentException(ex);145 } catch (InstantiationException ex) {146 throw new IllegalArgumentException(ex);147 }148 }149 150 public Boolean areAlgoParamsEqual() {151 Boolean retval = false;152 153 return retval;154 }155 156 public void createMissingAlgoParams(Long algorithmId,157 Set<String> missingParamNames) {158 159 //falls Werte auch verglichen werdne sollen160 //Map<String, Object> ecjAlgoParams161 //Set<String> missingParamNames = ecjAlgoParams.keySet();162 for (String paramname : missingParamNames) {163 AlgorithmParameter newAlgoParam = new AlgorithmParameter();164 newAlgoParam.setAlgorithmId(algorithmId);165 newAlgoParam.setDataTypeId(null);// TODO insert DatatypeId if not166 // exists (mapping first);167 newAlgoParam.setDescription(factory168 .createNamedOKBItemDescription("created from ECJ"));169 newAlgoParam.setName(factory170 .createNamedOKBItemName(paramname));171 port.addAlgorithmParameter(newAlgoParam);172 }173 }174 175 public void createMissingProblemParams(Long ProblemId,176 Set<String> missingParamNames) {177 178 //falls Werte auch verglichen werdne sollen179 //Map<String, Object> ecjProblemParams180 //Set<String> missingParamNames = ecjProblemParams.keySet();181 for (String paramname : missingParamNames) {182 ProblemParameter newProblemParam = new ProblemParameter();183 newProblemParam.setProblemId(ProblemId);184 newProblemParam.setDataTypeId(null);// TODO insert DatatypeId if not185 // exists (mapping first);186 newProblemParam.setDescription(factory187 .createNamedOKBItemDescription("created from ECJ"));188 newProblemParam.setName(factory189 .createNamedOKBItemName(paramname));190 port.addProblemParameter(newProblemParam);191 }192 }193 30 } 31 // OKBService srv = null; 32 // IOKBService port = null; 33 // ObjectFactory factory = new ObjectFactory(); 34 // 35 // public OKBServiceClient() { 36 // this.srv = new OKBService(); 37 // this.port = srv.getWSHttpBindingIOKBService1(); 38 // } 39 // 40 // public Long getPlatformId(String platformName) { 41 // Platform returnValue = Iterables.find( 42 // port.getPlatforms().getPlatform(), 43 // createNameFilter(platformName), null); 44 // 45 // return returnValue != null ? returnValue.getId() : null; 46 // } 47 // 48 // public Long getProblemId(String problemName) { 49 // Problem returnValue = Iterables.find(port.getProblems().getProblem(), 50 // createNameFilter(problemName), null); 51 // 52 // return returnValue != null ? returnValue.getId() : null; 53 // } 54 // 55 // public Long getProblemClassId(String problemClass) { 56 // ProblemClass returnValue = Iterables.find(port.getProblemClasses() 57 // .getProblemClass(), createNameFilter(problemClass), null); 58 // 59 // return returnValue != null ? returnValue.getId() : null; 60 // 61 // } 62 // 63 // public Long getAlgorithmClassId(String algorithmClassName) { 64 // AlgorithmClass returnValue = Iterables.find(port.getAlgorithmClasses() 65 // .getAlgorithmClass(), createNameFilter(algorithmClassName), 66 // null); 67 // 68 // return returnValue != null ? returnValue.getId() : null; 69 // 70 // } 71 // 72 // public Long getProblem(String problemName, Long problemClassId, 73 // Long platformId) { 74 // Problem problem = null; 75 // Iterator<Problem> it = port.getProblems().getProblem().iterator(); 76 // 77 // while (it.hasNext() && problem == null) { 78 // Problem tmpProblem = it.next(); 79 // if (platformId.equals(tmpProblem.getPlatformId()) 80 // && problemName.equals(tmpProblem.getName().getValue()) 81 // && problemClassId.equals(tmpProblem.getProblemClassId())) { 82 // 83 // problem = tmpProblem; 84 // } 85 // } 86 // return problem != null ? problem.getId() : null; 87 // } 88 // 89 // public Long getAlgorithmId(String algorithmName, /* Long algorithmClassId, */ 90 // Long platformId) { 91 // Algorithm algorithm = null; 92 // 93 // Iterator<Algorithm> it = port.getAlgorithms().getAlgorithm().iterator(); 94 // 95 // while (it.hasNext() && algorithm == null) { 96 // Algorithm tmpAlgo = it.next(); 97 // if (platformId.equals(tmpAlgo.getPlatformId()) 98 // && algorithmName.equals(tmpAlgo.getName().getValue()) 99 // // && algorithmClassId.equals(tmpAlgo.getAlgorithmClassId()) 100 // ) { 101 // algorithm = tmpAlgo; 102 // } 103 // } 104 // 105 // return algorithm != null ? algorithm.getId() : null; 106 // 107 // } 108 // 109 // public Map<String, Object> getAlgorithmParameterMap(Long algorithmId) { 110 // Map<String, Object> returnMap = new HashMap<String, Object>(); 111 // 112 // ArrayOfAlgorithmParameter algoParamList = port 113 // .getAlgorithmParameters(algorithmId); 114 // 115 // for (AlgorithmParameter algoParam : algoParamList 116 // .getAlgorithmParameter()) { 117 // returnMap.put(algoParam.getName().getValue(), null); 118 // } 119 // 120 // return returnMap; 121 // } 122 // 123 // public Map<String, Object> getProblemParameterMap(Long ProblemId) { 124 // Map<String, Object> returnMap = new HashMap<String, Object>(); 125 // 126 // ArrayOfProblemParameter algoParamList = port 127 // .getProblemParameters(ProblemId); 128 // 129 // for (ProblemParameter algoParam : algoParamList 130 // .getProblemParameter()) { 131 // returnMap.put(algoParam.getName().getValue(), null); 132 // } 133 // 134 // return returnMap; 135 // } 136 // 137 // 138 // 139 // private <T extends NamedOKBItem> T createNamedOKBItem(Class<T> clazz, 140 // String name) { 141 // try { 142 // T instance = clazz.newInstance(); 143 // instance.setName(factory.createNamedOKBItemName(name)); 144 // return instance; 145 // } catch (IllegalAccessException ex) { 146 // throw new IllegalArgumentException(ex); 147 // } catch (InstantiationException ex) { 148 // throw new IllegalArgumentException(ex); 149 // } 150 // } 151 // 152 // public Boolean areAlgoParamsEqual() { 153 // Boolean retval = false; 154 // 155 // return retval; 156 // } 157 // 158 // public void createMissingAlgoParams(Long algorithmId, 159 // Set<String> missingParamNames) { 160 // 161 // //falls Werte auch verglichen werdne sollen 162 // //Map<String, Object> ecjAlgoParams 163 // //Set<String> missingParamNames = ecjAlgoParams.keySet(); 164 // for (String paramname : missingParamNames) { 165 // AlgorithmParameter newAlgoParam = new AlgorithmParameter(); 166 // newAlgoParam.setAlgorithmId(algorithmId); 167 // newAlgoParam.setDataTypeId(null);// TODO insert DatatypeId if not 168 // // exists (mapping first); 169 // newAlgoParam.setDescription(factory 170 // .createNamedOKBItemDescription("created from ECJ")); 171 // newAlgoParam.setName(factory 172 // .createNamedOKBItemName(paramname)); 173 // port.addAlgorithmParameter(newAlgoParam); 174 // } 175 // } 176 // 177 // public void createMissingProblemParams(Long ProblemId, 178 // Set<String> missingParamNames) { 179 // 180 // //falls Werte auch verglichen werdne sollen 181 // //Map<String, Object> ecjProblemParams 182 // //Set<String> missingParamNames = ecjProblemParams.keySet(); 183 // for (String paramname : missingParamNames) { 184 // ProblemParameter newProblemParam = new ProblemParameter(); 185 // newProblemParam.setProblemId(ProblemId); 186 // newProblemParam.setDataTypeId(null);// TODO insert DatatypeId if not 187 // // exists (mapping first); 188 // newProblemParam.setDescription(factory 189 // .createNamedOKBItemDescription("created from ECJ")); 190 // newProblemParam.setName(factory 191 // .createNamedOKBItemName(paramname)); 192 // port.addProblemParameter(newProblemParam); 193 // } 194 // } 195 //}
Note: See TracChangeset
for help on using the changeset viewer.