Skip to main content
summaryrefslogtreecommitdiffstats
blob: da8aef522803111554063473f5a811d015ca5742 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
/*******************************************************************************
 * Copyright (c) 2012 Boeing.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     Boeing - initial API and implementation
 *******************************************************************************/
package org.eclipse.osee.orcs.rest.client.internal;

import java.net.URI;
import java.util.ArrayList;
import java.util.List;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.UriBuilder;
import org.eclipse.osee.framework.core.data.IOseeBranch;
import org.eclipse.osee.framework.core.data.OseeCodeVersion;
import org.eclipse.osee.jaxrs.client.JaxRsClient;
import org.eclipse.osee.jaxrs.client.OseeClientProperties;
import org.eclipse.osee.orcs.rest.client.OseeClient;
import org.eclipse.osee.orcs.rest.client.QueryBuilder;
import org.eclipse.osee.orcs.rest.client.internal.search.PredicateFactory;
import org.eclipse.osee.orcs.rest.client.internal.search.PredicateFactoryImpl;
import org.eclipse.osee.orcs.rest.client.internal.search.QueryBuilderImpl;
import org.eclipse.osee.orcs.rest.client.internal.search.QueryExecutorV1;
import org.eclipse.osee.orcs.rest.client.internal.search.QueryExecutorV1.BaseUriBuilder;
import org.eclipse.osee.orcs.rest.client.internal.search.QueryOptions;
import org.eclipse.osee.orcs.rest.model.Client;
import org.eclipse.osee.orcs.rest.model.search.artifact.Predicate;
import com.google.inject.Inject;
import com.sun.jersey.api.client.UniformInterfaceException;
import com.sun.jersey.api.client.WebResource;

/**
 * @author John Misinco
 * @author Roberto E. Escobar
 */
public class OseeClientImpl implements OseeClient, BaseUriBuilder {

   private PredicateFactory predicateFactory;
   private QueryExecutorV1 executor;

   private JaxRsClient client;

   @Inject
   public void setJaxRsClient(JaxRsClient client) {
      this.client = client;
   }

   public void start() {
      predicateFactory = new PredicateFactoryImpl();
      executor = new QueryExecutorV1(client, this);
   }

   public void stop() {
      predicateFactory = null;
      executor = null;
   }

   @Override
   public QueryBuilder createQueryBuilder(IOseeBranch branch) {
      QueryOptions options = new QueryOptions();
      List<Predicate> predicates = new ArrayList<Predicate>();
      return new QueryBuilderImpl(branch, predicates, options, predicateFactory, executor);
   }

   @Override
   public UriBuilder newBuilder() {
      String serverUri = OseeClientProperties.getApplicationServerAddress();
      return UriBuilder.fromUri(serverUri).path("orcs");
   }

   @Override
   public boolean isClientVersionSupportedByApplicationServer() {
      boolean result = false;
      URI uri = newBuilder().path("client").build();
      WebResource resource = client.createResource(uri);
      Client clientResult = null;
      try {
         clientResult = resource.accept(MediaType.APPLICATION_XML).get(Client.class);
         if (clientResult != null) {
            result = clientResult.getSupportedVersions().contains(OseeCodeVersion.getVersion());
         }
      } catch (UniformInterfaceException ex) {
         throw client.handleException(ex);
      }
      return result;
   }

   @Override
   public boolean isApplicationServerAlive() {
      boolean alive = false;
      try {
         isClientVersionSupportedByApplicationServer();
         alive = true;
      } catch (Exception ex) {
         alive = false;
      }
      return alive;
   }
}

Back to the top