Free cookie consent management tool by TermsFeed Policy Generator

source: branches/OKBJavaConnector/HLOKBWebClient/src/main/java/at/hl/okb/wsclient/OKBServiceClient.java @ 5249

Last change on this file since 5249 was 5249, checked in by mholper, 13 years ago

added some changed in Impl #1218

File size: 5.0 KB
RevLine 
[4963]1package at.hl.okb.wsclient;
2
[5229]3import static at.hl.okb.wsclient.Utilities.createNameFilter;
4
[5249]5import java.util.ArrayList;
[5248]6import java.util.HashMap;
[5242]7import java.util.Iterator;
[5249]8import java.util.List;
[5248]9import java.util.Map;
[4963]10
11import at.hl.wsclient.okb.Algorithm;
[5242]12import at.hl.wsclient.okb.AlgorithmClass;
[5248]13import at.hl.wsclient.okb.AlgorithmParameter;
14import at.hl.wsclient.okb.ArrayOfAlgorithmParameter;
[4963]15import at.hl.wsclient.okb.IOKBService;
[5242]16import at.hl.wsclient.okb.NamedOKBItem;
[4963]17import at.hl.wsclient.okb.OKBService;
[5229]18import at.hl.wsclient.okb.ObjectFactory;
[4963]19import at.hl.wsclient.okb.Platform;
20import at.hl.wsclient.okb.Problem;
[5242]21import at.hl.wsclient.okb.ProblemClass;
[4963]22
[5233]23import com.google.common.collect.Iterables;
24
[4963]25public class OKBServiceClient {
[5248]26  OKBService srv = null;
27  IOKBService port = null;
28  ObjectFactory factory = new ObjectFactory();
[4963]29
[5248]30  public OKBServiceClient() {
31    this.srv = new OKBService();
32    this.port = srv.getWSHttpBindingIOKBService1();
33  }
[5229]34
[5248]35  public Long getPlatformId(String platformName) {
36    Platform returnValue = Iterables.find(
37        port.getPlatforms().getPlatform(),
38        createNameFilter(platformName), null);
[5229]39
[5249]40    return returnValue != null ? returnValue.getId() : null;
[5248]41  }
[5249]42
[5248]43  public Long getProblemId(String problemName) {
[5249]44    Problem returnValue = Iterables.find(port.getProblems().getProblem(),
[5248]45        createNameFilter(problemName), null);
[5229]46
[5249]47    return returnValue != null ? returnValue.getId() : null;
48  }
[5242]49
[5248]50  public Long getProblemClassId(String problemClass) {
51    ProblemClass returnValue = Iterables.find(port.getProblemClasses()
52        .getProblemClass(), createNameFilter(problemClass), null);
[5242]53
[5249]54    return returnValue != null ? returnValue.getId() : null;
[5229]55
[5248]56  }
[5233]57
[5248]58  public Long getAlgorithmClassId(String algorithmClassName) {
59    AlgorithmClass returnValue = Iterables.find(port.getAlgorithmClasses()
60        .getAlgorithmClass(), createNameFilter(algorithmClassName),
61        null);
[5233]62
[5249]63    return returnValue != null ? returnValue.getId() : null;
[5229]64
[5248]65  }
66
67  public Long getProblem(String problemName, Long problemClassId,
68      Long platformId) {
69    Problem problem = null;
70    Iterator<Problem> it = port.getProblems().getProblem().iterator();
71
72    while (it.hasNext() && problem == null) {
73      Problem tmpProblem = it.next();
74      if (platformId.equals(tmpProblem.getPlatformId())
75          && problemName.equals(tmpProblem.getName().getValue())
76          && problemClassId.equals(tmpProblem.getProblemClassId())) {
77
78        problem = tmpProblem;
79      }
80    }
[5249]81    return problem != null ? problem.getId() : null;
[5248]82  }
83
[5249]84  public Long getAlgorithmId(String algorithmName, /* Long algorithmClassId, */
85  Long platformId) {
[5248]86    Algorithm algorithm = null;
[5249]87
[5248]88    Iterator<Algorithm> it = port.getAlgorithms().getAlgorithm().iterator();
89
90    while (it.hasNext() && algorithm == null) {
91      Algorithm tmpAlgo = it.next();
92      if (platformId.equals(tmpAlgo.getPlatformId())
93          && algorithmName.equals(tmpAlgo.getName().getValue())
[5249]94      // && algorithmClassId.equals(tmpAlgo.getAlgorithmClassId())
95      ) {
[5248]96        algorithm = tmpAlgo;
97      }
98    }
[5249]99
100    return algorithm != null ? algorithm.getId() : null;
101
[4963]102  }
[5229]103
[5249]104  // public Map<String, ECJDataTypeEnum> getAlgorithParameter(Long
105  // algorithmId) {
106  // Map<String, AlgorithmParameter> returnMap = new HashMap<String,
107  // AlgorithmParameter>();
108  //
109  // AlgorithmData algoData = port.getAlgorithmData(algorithmId);
110  //
111  // ArrayOfAlgorithmParameter algoParamList =
112  // port.getAlgorithmParameters(algorithmId);
113  //
114  // for (AlgorithmParameter algoParam:algoParamList.getAlgorithmParameter())
115  // {
116  // mapOKBDataTypetoECJDataTypeEnum()
117  // port.getDataType(algoParam.getDataTypeId()).getName().getValue()) {
118  //
119  // }
120  // returnMap.put(algoParam.getName().getValue(),
121  // port.getDataType(algoParam.getDataTypeId()).getName().getValue());
122  // }
123  //
124  // return returnMap;
125  // }
126
[5248]127  private <T extends NamedOKBItem> T createNamedOKBItem(Class<T> clazz,
128      String name) {
129    try {
130      T instance = clazz.newInstance();
131      instance.setName(factory.createNamedOKBItemName(name));
132      return instance;
133    } catch (IllegalAccessException ex) {
134      throw new IllegalArgumentException(ex);
135    } catch (InstantiationException ex) {
136      throw new IllegalArgumentException(ex);
137    }
[4963]138  }
[5249]139 
140  public Boolean areAlgoParamsEqual() {
141    Boolean retval = false;
142   
143   
144    return retval;
145  }
[4963]146
[5249]147  public void createMissingAlgoParams(Long algorithmId,
148      Map<String, Object> ecjAlgoParams) {
149
150    List<String> missingParams = new ArrayList<String>();
151
152    ArrayOfAlgorithmParameter hlAlgoParams = port
153        .getAlgorithmParameters(algorithmId);
154    Map<String, Object> hlAlgoParamMap = new HashMap<String, Object>();
155
156    for (AlgorithmParameter algoParam : hlAlgoParams
157        .getAlgorithmParameter()) {
158      hlAlgoParamMap.put(algoParam.getName().getValue(), null); // value
159      // hangs
160      // on
161      // Experiments
162    }
163
164    String[] ecjparamNames = (String[]) ecjAlgoParams.keySet().toArray();
165
166    for (int i = 0; i < ecjparamNames.length; i++) {
167      if (!hlAlgoParamMap.containsKey(ecjparamNames[i])) {
168        missingParams.add(new String(ecjparamNames[i]));
169      }
170    }
171
172  }
[4963]173}
Note: See TracBrowser for help on using the repository browser.