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
Line 
1package at.hl.okb.wsclient;
2
3import static at.hl.okb.wsclient.Utilities.createNameFilter;
4
5import java.util.ArrayList;
6import java.util.HashMap;
7import java.util.Iterator;
8import java.util.List;
9import java.util.Map;
10
11import at.hl.wsclient.okb.Algorithm;
12import at.hl.wsclient.okb.AlgorithmClass;
13import at.hl.wsclient.okb.AlgorithmParameter;
14import at.hl.wsclient.okb.ArrayOfAlgorithmParameter;
15import at.hl.wsclient.okb.IOKBService;
16import at.hl.wsclient.okb.NamedOKBItem;
17import at.hl.wsclient.okb.OKBService;
18import at.hl.wsclient.okb.ObjectFactory;
19import at.hl.wsclient.okb.Platform;
20import at.hl.wsclient.okb.Problem;
21import at.hl.wsclient.okb.ProblemClass;
22
23import com.google.common.collect.Iterables;
24
25public class OKBServiceClient {
26  OKBService srv = null;
27  IOKBService port = null;
28  ObjectFactory factory = new ObjectFactory();
29
30  public OKBServiceClient() {
31    this.srv = new OKBService();
32    this.port = srv.getWSHttpBindingIOKBService1();
33  }
34
35  public Long getPlatformId(String platformName) {
36    Platform returnValue = Iterables.find(
37        port.getPlatforms().getPlatform(),
38        createNameFilter(platformName), null);
39
40    return returnValue != null ? returnValue.getId() : null;
41  }
42
43  public Long getProblemId(String problemName) {
44    Problem returnValue = Iterables.find(port.getProblems().getProblem(),
45        createNameFilter(problemName), null);
46
47    return returnValue != null ? returnValue.getId() : null;
48  }
49
50  public Long getProblemClassId(String problemClass) {
51    ProblemClass returnValue = Iterables.find(port.getProblemClasses()
52        .getProblemClass(), createNameFilter(problemClass), null);
53
54    return returnValue != null ? returnValue.getId() : null;
55
56  }
57
58  public Long getAlgorithmClassId(String algorithmClassName) {
59    AlgorithmClass returnValue = Iterables.find(port.getAlgorithmClasses()
60        .getAlgorithmClass(), createNameFilter(algorithmClassName),
61        null);
62
63    return returnValue != null ? returnValue.getId() : null;
64
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    }
81    return problem != null ? problem.getId() : null;
82  }
83
84  public Long getAlgorithmId(String algorithmName, /* Long algorithmClassId, */
85  Long platformId) {
86    Algorithm algorithm = null;
87
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())
94      // && algorithmClassId.equals(tmpAlgo.getAlgorithmClassId())
95      ) {
96        algorithm = tmpAlgo;
97      }
98    }
99
100    return algorithm != null ? algorithm.getId() : null;
101
102  }
103
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
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    }
138  }
139 
140  public Boolean areAlgoParamsEqual() {
141    Boolean retval = false;
142   
143   
144    return retval;
145  }
146
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  }
173}
Note: See TracBrowser for help on using the repository browser.