ivy.html.startref allows me to get a link to another process starts. Unfortunately this only seems to work within the same project.

Is there any way I can get a link to the process start of another project? Using ivy.html.startref("Projectname/Processname/startName.ivp") or ivy.html.startref("../Projectname/Processname/startName.ivp") don't seem to work.

asked 27.11.2014 at 08:25

ahatius's gravatar image

ahatius
7191012
accept rate: 0%

edited 27.11.2014 at 08:31

Reto%20Weiss's gravatar image

Reto Weiss ♦♦
4.9k182656


The ivy.html.startref only works for process starts that are in the same project as the callee. If you want to get a link to a process starts that is outside of your project you can use the following ivyScript snippet:

import ch.ivyteam.ivy.request.IHttpRequest;
import java.util.Set;
import ch.ivyteam.ivy.workflow.IProcessStart;

if (ivy.request instanceof IHttpRequest)
{
    Set processStarts = ivy.wf.findProcessStartsBySignature("myProcessStart()");
  IProcessStart processStart = processStarts.iterator().next() as IProcessStart;
  String fullRequestPath = processStart.getFullRequestPath();
    IHttpRequest httpRequest = ivy.request as IHttpRequest;
    String requestUri = httpRequest.getHttpServletRequest().getContextPath() + "/process/"+fullRequestPath;
}
link

answered 28.11.2014 at 13:40

Reto%20Weiss's gravatar image

Reto Weiss ♦♦
4.9k182656
accept rate: 74%

Hi @reto-weiss I have module A is dependent on B, Can i use this to get startlink of A from B with this way?

(31.08.2016 at 03:56) trungdv trungdv's gravatar image

I've tried with above solution with Axon ivy 6.3 , but it throw exception NoSuchElementException on line processStarts.iterator().next() as IProcessStart;

So i tried another one and it works:

 public String getStartUrl(boolean isAbsoluteLink, String startProcessPoint) throws Exception {
     String requestPath = SecurityServiceUtils.findProcessByUserFriendlyRequestPath(startProcessPoint);
        if (isAbsoluteLink) {
          UrlDetector urlDetector = new UrlDetector();
          String serverUrl = urlDetector.getBaseURL(FacesContext.getCurrentInstance());
          return serverUrl + requestPath;
        }
        String language = URLEncoder.encode(Ivy.session().getContentLocale().getLanguage(), "UTF-8");
        return "/" + RequestUriFactory.getIvyContextName(ServerFactory.getServer().getApplicationConfigurationManager())
            + requestPath + "?language=" + language;
      }

And below is SecurityServiceUtils.findProcessByUserFriendlyRequestPath():

public static String findProcessByUserFriendlyRequestPath(String processStartSignature) throws Exception {
return ServerFactory.getServer().getSecurityManager().executeAsSystem(new Callable<String>() {

  @Override
  public String call() throws Exception {
    ProcessStartCollector processStartCollector = new ProcessStartCollector(Ivy.wf().getApplication());
    IProcessStart processStart =
        processStartCollector.findProcessStartByUserFriendlyRequestPath(processStartSignature);
    if (processStart != null) {
      try {
        return "/pro/" + processStart.getFullRequestPath();
      } catch (Exception e) {
        Ivy.log().error(e);
        return StringUtils.EMPTY;
      }
    }
    return StringUtils.EMPTY;
  }
});

}

And the class ProcessStartCollector

import java.net.MalformedURLException;
import java.net.URI;
import java.util.List;
import java.util.concurrent.Callable;
import javax.faces.context.FacesContext;
import org.apache.commons.lang3.StringUtils;
import ch.ivy.addon.portalkit.support.UrlDetector;
import ch.ivyteam.ivy.application.ActivityState;
import ch.ivyteam.ivy.application.IApplication;
import ch.ivyteam.ivy.application.IProcessModel;
import ch.ivyteam.ivy.application.IProcessModelVersion;
import ch.ivyteam.ivy.environment.Ivy;
import ch.ivyteam.ivy.request.RequestUriFactory;
import ch.ivyteam.ivy.server.ServerFactory;
import ch.ivyteam.ivy.workflow.IProcessStart;
import ch.ivyteam.ivy.workflow.IWorkflowProcessModelVersion;
import ch.ivyteam.ivy.workflow.WorkflowNavigationUtil;

public class ProcessStartCollector {

  private final IApplication application;

  public ProcessStartCollector(IApplication application) {
    this.application = application;
  }

  public IProcessStart findProcessStartByUserFriendlyRequestPath(String requestPath) {
    if (isActive(this.application)) {
      List<IProcessModel> processModels = this.application.getProcessModelsSortedByName();

      for (IProcessModel processModel : processModels) {

        if (isActive(processModel)) {
          IProcessModelVersion processModelVersion = processModel.getReleasedProcessModelVersion();

          if (isActive(processModelVersion)) {
            IWorkflowProcessModelVersion workflowPmv =
                WorkflowNavigationUtil.getWorkflowProcessModelVersion(processModelVersion);
            IProcessStart processStart = workflowPmv.findProcessStartByUserFriendlyRequestPath(requestPath);
            if (processStart != null) {
              return processStart;
            }
          }
        }
      }
    }
    return null;
  }

  public String findACMLink() throws Exception {
    return ServerFactory.getServer().getSecurityManager().executeAsSystem(new Callable<String>() {
      @Override
      public String call() throws Exception {
        ProcessStartCollector collector = new ProcessStartCollector(application);
        IProcessStart process =
            collector.findProcessStartByUserFriendlyRequestPath("BusinessProcesses/AdHocWF/start.ivp");
        if (process != null) {
          URI processUri =
              RequestUriFactory.createProcessStartUri(ServerFactory.getServer().getApplicationConfigurationManager(),
                  process);
          return getServerUrl() + processUri.toString();
        }
        return StringUtils.EMPTY;
      }
    });
  }

  private String getServerUrl() {
    UrlDetector urlDetector = new UrlDetector();
    String serverUrl = StringUtils.EMPTY;
    try {
      String baseUrl = urlDetector.getBaseURL(FacesContext.getCurrentInstance());
      serverUrl = urlDetector.getHost(baseUrl);
    } catch (MalformedURLException e) {
      Ivy.log().error(e);
    }
    return serverUrl;
  }

  private boolean isActive(IProcessModelVersion processModelVersion) {
    return processModelVersion != null && ActivityState.ACTIVE.equals(processModelVersion.getActivityState());
  }

  private boolean isActive(IProcessModel processModel) {
    return ActivityState.ACTIVE.equals(processModel.getActivityState());
  }

  private boolean isActive(IApplication application) {
    return ActivityState.ACTIVE.equals(application.getActivityState());
  }
}

Hope it's helpful

link

answered 21.10.2016 at 04:35

trungdv's gravatar image

trungdv
49592101103
accept rate: 52%

Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "Title")
  • image?![alt text](/path/img.jpg "Title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Tags:

×75
×33
×4

Asked: 27.11.2014 at 08:25

Seen: 2,850 times

Last updated: 21.10.2016 at 04:35