Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
01/08/11 12:21:05 (14 years ago)
Author:
bfarka
Message:

restructure of service project #1218

Location:
branches/OKBJavaConnector/HLOKBWebClient/src
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • branches/OKBJavaConnector/HLOKBWebClient/src/main/java/at/hl/okb/wsclient/OKBServiceClient.java

    r5233 r5242  
    33import static at.hl.okb.wsclient.Utilities.createNameFilter;
    44
    5 import java.security.KeyManagementException;
    6 import java.security.NoSuchAlgorithmException;
    7 import java.util.ArrayList;
    8 import java.util.HashMap;
    9 import java.util.List;
    10 import java.util.Map;
    11 
    12 import javax.net.ssl.HttpsURLConnection;
    13 import javax.net.ssl.SSLContext;
    14 import javax.net.ssl.TrustManager;
    15 import javax.net.ssl.X509TrustManager;
     5import java.util.Iterator;
    166
    177import at.hl.wsclient.okb.Algorithm;
    18 import at.hl.wsclient.okb.AlgorithmParameter;
    19 import at.hl.wsclient.okb.ArrayOfAlgorithm;
    20 import at.hl.wsclient.okb.ArrayOfAlgorithmParameter;
    21 import at.hl.wsclient.okb.ArrayOfProblem;
     8import at.hl.wsclient.okb.AlgorithmClass;
    229import at.hl.wsclient.okb.IOKBService;
     10import at.hl.wsclient.okb.NamedOKBItem;
    2311import at.hl.wsclient.okb.OKBService;
    2412import at.hl.wsclient.okb.ObjectFactory;
    2513import at.hl.wsclient.okb.Platform;
    2614import at.hl.wsclient.okb.Problem;
     15import at.hl.wsclient.okb.ProblemClass;
    2716
    2817import com.google.common.collect.Iterables;
     
    3120    OKBService srv = null;
    3221    IOKBService port = null;
    33 
    34     // hack for allowing self signed certificates
    35     static {
    36   // Create a trust manager that does not validate certificate chains
    37   TrustManager[] trustAllCerts = new TrustManager[] { new X509TrustManager() {
    38       public java.security.cert.X509Certificate[] getAcceptedIssuers() {
    39     return new java.security.cert.X509Certificate[] {};
    40       }
    41 
    42       public void checkClientTrusted(
    43         java.security.cert.X509Certificate[] certs, String authType) {
    44       }
    45 
    46       public void checkServerTrusted(
    47         java.security.cert.X509Certificate[] certs, String authType) {
    48       }
    49   } };
    50 
    51   SSLContext sc;
    52   try {
    53       sc = SSLContext.getInstance("SSL");
    54       sc.init(null, trustAllCerts, new java.security.SecureRandom());
    55       HttpsURLConnection
    56         .setDefaultSSLSocketFactory(sc.getSocketFactory());
    57   } catch (NoSuchAlgorithmException e) {
    58       throw new RuntimeException(e);
    59   } catch (KeyManagementException e) {
    60       throw new RuntimeException(e);
    61   }
    62 
    63     }
     22    ObjectFactory factory = new ObjectFactory();
    6423
    6524    public OKBServiceClient() {
     
    7130  Platform returnValue = Iterables.find(
    7231    port.getPlatforms().getPlatform(),
    73     createNameFilter(platformName));
    74   if (returnValue == null)
    75       createPlatform(platformName);
     32    createNameFilter(platformName), null);
    7633
    77   returnValue = Iterables.find(port.getPlatforms().getPlatform(),
    78     createNameFilter(platformName));
     34  return returnValue.getId();
     35    }
     36
     37    public Long getProblemClassId(String problemClass) {
     38  ProblemClass returnValue = Iterables.find(port.getProblemClasses()
     39    .getProblemClass(), createNameFilter(problemClass), null);
     40
    7941  return returnValue.getId();
    8042
    8143    }
    8244
    83     private void createPlatform(String name) {
     45    public Long getAlgorithmClassId(String algorithmClassName) {
     46  AlgorithmClass returnValue = Iterables.find(port.getAlgorithmClasses()
     47    .getAlgorithmClass(), createNameFilter(algorithmClassName),
     48    null);
    8449
    85   ObjectFactory factory = new ObjectFactory();
    86   Platform platform = factory.createPlatform();
    87 
    88   platform.setName(factory.createNamedOKBItemName(name));
    89   port.addPlatform(platform);
    90     }
    91 
    92     public Long getAlgorithmId(String algorithmName) {
    93   Long algorithmId = null;
    94 
    95   ArrayOfAlgorithm allAlgorithms = port.getAlgorithms();
    96   for (Algorithm algo : allAlgorithms.getAlgorithm()) {
    97       if (algo.getName().getValue() == algorithmName) {
    98     algorithmId = algo.getId();
    99       }
    100   }
    101   return algorithmId;
    102     }
    103 
    104     public Long getProblemId(String problemName) {
    105   Long problemId = null;
    106 
    107   ArrayOfProblem allProblems = port.getProblems();
    108   for (Problem problem : allProblems.getProblem()) {
    109       if (problem.getName().getValue() == problemName) {
    110     problemId = problem.getId();
    111       }
    112   }
    113   return problemId;
    114     }
    115 
    116     public void checkAlgoParamsExists(Long algorithmId,
    117       Map<String, Object> ecjAlgoParams) {
    118 
    119   List<String> missingParams = new ArrayList<String>();
    120 
    121   ArrayOfAlgorithmParameter hlAlgoParams = port
    122     .getAlgorithmParameters(algorithmId);
    123   Map<String, Object> hlAlgoParamMap = new HashMap<String, Object>();
    124 
    125   for (AlgorithmParameter algoParam : hlAlgoParams
    126     .getAlgorithmParameter()) {
    127       hlAlgoParamMap.put(algoParam.getName().getValue(), null); // value
    128                       // hangs
    129                       // on
    130                       // Experiments
    131   }
    132 
    133   String[] ecjparamNames = (String[]) ecjAlgoParams.keySet().toArray();
    134 
    135   for (int i = 0; i < ecjparamNames.length; i++) {
    136       if (!hlAlgoParamMap.containsKey(ecjparamNames[i])) {
    137     missingParams.add(new String(ecjparamNames[i]));
    138       }
    139   }
     50  return returnValue.getId();
    14051
    14152    }
    14253
     54    public Long getProblem(String problemName, Long problemClassId,
     55      Long platformId) {
     56  Problem problem = null;
     57  Iterator<Problem> it = port.getProblems().getProblem().iterator();
     58 
     59  while (it.hasNext() && problem == null) {
     60      Problem tmpProblem = it.next();
     61      if (platformId.equals(tmpProblem.getPlatformId())
     62        && problemName.equals(tmpProblem.getName().getValue())
     63        && problemClassId.equals(tmpProblem.getProblemClassId())) {
     64   
     65   
     66   
     67    problem = tmpProblem;
     68      }
     69  }
     70  return problem.getId();
     71    }
     72
     73   
     74    public Long getAlgorithm(String algorithmName, Long algorithmClassId,
     75      Long platformId) {
     76  Algorithm algorithm = null;
     77  Iterator<Algorithm> it = port.getAlgorithms().getAlgorithm().iterator();
     78 
     79  while (it.hasNext() && algorithm == null) {
     80      Algorithm tmpAlgo = it.next();
     81      if (platformId.equals(tmpAlgo.getPlatformId())
     82        && algorithmName.equals(tmpAlgo.getName().getValue())
     83        && algorithmClassId.equals(tmpAlgo.getAlgorithmClassId())) {
     84    algorithm = tmpAlgo;
     85      }
     86  }
     87  return algorithm.getId();
     88    }
     89
     90   
     91    private <T extends NamedOKBItem> T createNamedOKBItem(Class<T> clazz,
     92      String name) {
     93  try {
     94      T instance = clazz.newInstance();
     95      instance.setName(factory.createNamedOKBItemName(name));
     96      return instance;
     97  } catch (IllegalAccessException ex) {
     98      throw new IllegalArgumentException(ex);
     99  } catch (InstantiationException ex) {
     100      throw new IllegalArgumentException(ex);
     101  }
     102    }
     103
    143104}
  • branches/OKBJavaConnector/HLOKBWebClient/src/main/java/at/hl/okb/wsclient/Utilities.java

    r5229 r5242  
    22
    33import at.hl.wsclient.okb.NamedOKBItem;
     4import at.hl.wsclient.okb.Problem;
    45
    56import com.google.common.base.Predicate;
     
    2223  }
    2324 
     25 
     26  private static class ProblemFilter implements Predicate<Problem>
     27  {
     28      private final String problemName;
     29      private final String problemClass;
     30     
     31      public ProblemFilter(String problemName, String problemClass)
     32      {
     33    this.problemClass = problemClass;
     34    this.problemName = problemName;
     35      }
     36
     37      @Override
     38      public boolean apply(Problem input) {
     39    // TODO Auto-generated method stub
     40    return false;
     41      }
     42  }
     43 
     44 
    2445  public static Predicate<NamedOKBItem> createNameFilter(String name)
    2546  {
  • branches/OKBJavaConnector/HLOKBWebClient/src/test/java/at/hl/okb/wsclient/OKBClientTest.java

    r5229 r5242  
    11package at.hl.okb.wsclient;
    22
     3
     4import junit.framework.Assert;
    35
    46import org.junit.Test;
     
    1517      public void testGetPlatform()
    1618  {
    17       client.getPlatformId("ECJ");
     19      Assert.assertNotNull(client.getPlatformId("ECJ"));
    1820  }
    19 
     21 
     22  @Test
     23      public void testGetProblemClass()
     24  {
     25      Assert.assertNotNull(client.getProblemClassId("ECJ"));
     26  }
     27  @Test
     28  public void testGetAlgorithmClass()
     29  {
     30      Assert.assertNotNull(client.getAlgorithmClassId("ECJ"));
     31  }
     32 
    2033}
Note: See TracChangeset for help on using the changeset viewer.