Skip to main content
summaryrefslogtreecommitdiffstats
blob: 37d9a11c29fd931eca37ab3956e52c7185820d1d (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
/*******************************************************************************
 * Copyright (c) 2004, 2007 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.framework.skynet.core.artifact;

import java.io.UnsupportedEncodingException;
import java.net.URL;
import java.util.HashMap;
import java.util.Map;
import java.util.logging.Level;
import org.eclipse.osee.framework.core.client.ClientSessionManager;
import org.eclipse.osee.framework.core.client.server.HttpUrlBuilderClient;
import org.eclipse.osee.framework.core.data.OseeServerContext;
import org.eclipse.osee.framework.core.enums.PresentationType;
import org.eclipse.osee.framework.jdk.core.type.OseeCoreException;
import org.eclipse.osee.framework.jdk.core.util.HttpUrlBuilder;
import org.eclipse.osee.framework.jdk.core.util.Strings;
import org.eclipse.osee.framework.logging.OseeLog;
import org.eclipse.osee.framework.skynet.core.internal.Activator;
import org.eclipse.osee.framework.skynet.core.utility.OseeInfo;

/**
 * @author Roberto E. Escobar
 */
public class ArtifactURL {

   public static URL getOpenInOseeLink(final Artifact artifact, String cmd, PresentationType presentationType) throws OseeCoreException {
      Map<String, String> parameters = new HashMap<>();
      parameters.put("sessionId", ClientSessionManager.getSessionId());
      parameters.put("context", "osee/loopback");
      parameters.put("guid", artifact.getGuid());
      parameters.put("branchUuid", String.valueOf(artifact.getBranch().getGuid()));
      parameters.put("isDeleted", String.valueOf(artifact.isDeleted()));

      if (artifact.isHistorical() && presentationType != PresentationType.DIFF && presentationType != PresentationType.F5_DIFF) {
         parameters.put("transactionId", String.valueOf(artifact.getTransaction()));
      }

      parameters.put("cmd", cmd);
      String urlString = getPermanentLinkBaseUrl(OseeServerContext.CLIENT_LOOPBACK_CONTEXT, parameters);
      URL url = null;
      try {
         url = new URL(urlString);
      } catch (Exception ex) {
         OseeCoreException.wrapAndThrow(ex);
      }
      return url;
   }

   public static URL getOpenInOseeLink(final Artifact artifact, PresentationType presentationType) throws OseeCoreException {
      return getOpenInOseeLink(artifact, "open.artifact", presentationType);
   }

   public static String getPermanentLinkBaseUrl(String context, Map<String, String> parameters) throws OseeCoreException {
      try {
         return HttpUrlBuilder.createURL(getSelectedPermanenrLinkUrl(), context, parameters);
      } catch (UnsupportedEncodingException ex) {
         throw OseeCoreException.wrap(ex);
      }
   }

   public static String getSelectedPermanenrLinkUrl() throws OseeCoreException {
      HttpUrlBuilderClient httpBuilder = HttpUrlBuilderClient.getInstance();
      String address = null;
      if (httpBuilder.isUseConnectedServerUrl()) {
         address = httpBuilder.getApplicationServerPrefix();
      } else {
         try {
            address = getPermanentBaseUrl();
         } catch (Exception ex) {
            OseeLog.log(Activator.class, Level.WARNING, ex);
         }
         if (!Strings.isValid(address)) {
            address = httpBuilder.getApplicationServerPrefix();
         }
      }
      return normalize(address);
   }

   public static String getPermanentBaseUrl() throws OseeCoreException {
      String address = OseeInfo.getValue("osee.permanent.base.url");
      return normalize(address);
   }

   private static String normalize(String address) {
      String toReturn = address;
      if (Strings.isValid(toReturn) && !toReturn.endsWith("/")) {
         toReturn += "/";
      }
      return toReturn;
   }
}

Back to the top