<?xml version="1.0" encoding="utf-8"?>
<rss xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title>Answers to: how to get root folder of project where user start ?</title><link>https://answers.axonivy.com/questions/2538/how-to-get-root-folder-of-project-where-user-start</link><description>&lt;p&gt;hi all&lt;/p&gt;
&lt;p&gt;i have a project A with a startlink, this project depend on project B (B contain some commons ivy component).
Now user start page by that startlink, it will open a page which use come commons component from B)&lt;/p&gt;
&lt;p&gt;Now i need to get root folder of project A, i refer this &lt;a href="http://answers.axonivy.com/questions/2143/how-to-get-webcontent-folder-in-ivy-project"&gt;post&lt;/a&gt; but it just work fine if it run in project A, when i call it on commons component (project B) then it return the folder of B.&lt;/p&gt;
&lt;p&gt;My question is: is there any api to get root folder (maybe webcontent) of project where user start the startlink (like project A in above example)?&lt;/p&gt;
&lt;p&gt;Thanks&lt;/p&gt;</description><atom:link href="https://answers.axonivy.com/questions/2538/how-to-get-root-folder-of-project-where-user-start" rel="self"></atom:link><language>en</language><lastBuildDate>Tue, 28 Mar 2017 08:50:28 -0400</lastBuildDate><item><title>Comment by Alex Suter on Alex Suter's answer</title><link>https://answers.axonivy.com/questions/2538/how-to-get-root-folder-of-project-where-user-start#2543</link><description>&lt;p&gt;This concept only works for Callable Subprocess.&lt;/p&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Alex Suter</dc:creator><pubDate>Tue, 28 Mar 2017 08:50:28 -0400</pubDate><guid>https://answers.axonivy.com/questions/2538/how-to-get-root-folder-of-project-where-user-start#2543</guid></item><item><title>Comment by trungdv on Alex Suter's answer</title><link>https://answers.axonivy.com/questions/2538/how-to-get-root-folder-of-project-where-user-start#2541</link><description>&lt;p&gt;hi &lt;a href="http://answers.axonivy.com/users/710/alex-suter"&gt;&lt;a href="http://answers.axonivy.com/users/710/alex-suter"&gt;@Alex Suter&lt;/a&gt;&lt;/a&gt; ♦♦&lt;/p&gt;
&lt;p&gt;Thanks for your fast response, yes you're right, it's B is a framework.
Can you tell me what will happen if i use signal or overriding process? can i find root request on that stack?&lt;/p&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">trungdv</dc:creator><pubDate>Tue, 28 Mar 2017 04:13:49 -0400</pubDate><guid>https://answers.axonivy.com/questions/2538/how-to-get-root-folder-of-project-where-user-start#2541</guid></item><item><title>Answer by Alex Suter</title><link>https://answers.axonivy.com/questions/2538/how-to-get-root-folder-of-project-where-user-start/2540</link><description>&lt;p&gt;Ivy puts all requests on a stack. There is an API to access this stack. But you can't directly access the initial process model version over &lt;code&gt;Ivy.request()&lt;/code&gt;. I extended the example with the method &lt;code&gt;findRootProcessModelVersionRequest()&lt;/code&gt;. This method finds the initial (root) &lt;code&gt;ProcessModelVersionRequest&lt;/code&gt;.&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Optional;

import org.eclipse.core.resources.IFolder;

import ch.ivyteam.ivy.environment.Ivy;
import ch.ivyteam.ivy.request.IProcessModelVersionRequest;
import ch.ivyteam.ivy.request.IRequest;
import ch.ivyteam.ivy.security.internal.SecurityManager;

public class WebContentResourceLoader {

    public Path getResource(String relativeToWebContent) {
        return findResource(relativeToWebContent)
                .orElseThrow(() -&amp;gt; 
                new RuntimeException("Resource at webContent/" + relativeToWebContent + " cannot be found"));
    }

    public Optional&amp;lt;Path&amp;gt; findResource(String relativeToWebContent) {
        return getWebContentFolder()
                .map(f -&amp;gt; f.getFile(relativeToWebContent))
                .map(f -&amp;gt; f.getLocationURI())
                .map(u -&amp;gt; Paths.get(u))
                .filter(p -&amp;gt; Files.exists(p));
    }

    private static Optional&amp;lt;IFolder&amp;gt; getWebContentFolder() {
        try {
            return Optional.ofNullable(SecurityManager
                    .getSecurityManager()
                    .executeAsSystem(
                            () -&amp;gt; findRootProcessModelVersionRequest().getProcessModelVersion().getProject().getFolder("webContent")
            ));
        } catch (Exception failToGetWebContent) {
            throw new RuntimeException("Fail to reach webContent folder",
                    failToGetWebContent);
        }
    }

    private static IProcessModelVersionRequest findRootProcessModelVersionRequest() 
    {
        IProcessModelVersionRequest rootProcessModelVersionRequest = Ivy.request();
        IRequest request = rootProcessModelVersionRequest;
        do {
            request = request.getParentRequest();
            if (request instanceof IProcessModelVersionRequest) {
                rootProcessModelVersionRequest = (IProcessModelVersionRequest) request;
            }
        } while (request != null);
        return rootProcessModelVersionRequest;
    }
}
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;This will work if B is a &lt;em&gt;Callable Sub Process&lt;/em&gt;.  If you call B with a &lt;em&gt;Trigger&lt;/em&gt;, this won't work. There will be a new task, which will ends up in a complete new request.  In this case you have to pass the parameters through process data.&lt;/p&gt;
&lt;p&gt;Note: You have to think about your design. Projects A depends on project B (A -&amp;gt; B). Now you create a implicit dependency backwards. A knows B and B knows A implicit. In my opinion that only makes sense, if B is something like a framework. Which seems to be the case - you call it "common components". &lt;/p&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Alex Suter</dc:creator><pubDate>Mon, 27 Mar 2017 20:24:53 -0400</pubDate><guid>https://answers.axonivy.com/questions/2538/how-to-get-root-folder-of-project-where-user-start/2540</guid></item></channel></rss>