FME workspaces are created through FME Workbench and can be published to an FME Server repository so that multiple users can access them. Workspaces in the FME Server repository can also be downloaded, modified, and then published again.
Note: A workspace is a type of repository item. The concepts in this section also apply to other repository items such as custom formats and custom transformers. A workspace normally has an FMW file extension, whereas custom formats have an FDS file extension and custom transformers have an FMX file extension.
A default installation of FME Server comes with a number of sample workspaces, but most users create their own workspaces. In this section, it is assumed you will either use one of the demo workspaces or create a workspace of your own using FME Workbench.
To List Workspaces in a Repository
Workspace names can be quickly listed using repository methods that get the workspace summaries of a workspace. More detailed information about workspaces can be fetched with the URIs provided.
httpRequest.open("GET", "/fmerest/repositories/"+name+".json?token="+token_, true);
httpRequest.onreadystatechange = function()
{
if (httpRequest.readyState == 4)
{
if (httpRequest.status == 200)
{
var reply = eval("(" + httpRequest.responseText + ")");
if (typeof(reply.serviceResponse.repository.workspaces) != 'undefined')
{
var workspaces = reply.serviceResponse.repository.workspaces;
for (var i in workspaces)
{
println(workspaces[i].name);
}
}
else
{
println("No Workspaces Found");
}
}
else
{
println("Error: "+httpRequest.responseText);
}
}
}
httpRequest.send(null);
To Add Workspaces to a Repository
Use FME Workbench to add a workspace to a repository.
To Remove Workspaces in a Repository
To remove a workspace in a repository, the repository name and the workspace name are required.
httpRequest.open("DELETE", "/fmerest/repositories/"+repositoryName+"/"+workspaceName+".json?token="+token_, true);
httpRequest.onreadystatechange = function()
{
if (httpRequest.readyState == 4)
{
if (httpRequest.status == 200)
{
println("Workspace removed");
}
else
{
println("Failed to remove workspace");
}
}
}
httpRequest.send(null);
To Dynamically Build a Form from Published Parameters
This example requests the parameters associated with a workspace and then builds a form dynamically. The advantage of this method is the code does not need to be modified if the workspace gets re-uploaded with new parameters.
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<script>
/**
* Parse the JSOn response and build a full form
*/
function parseFullFormJSON(inResult){
//parse the JSON response
var jsonDoc = JSON.parse(inResult);
var container = document.forms['fmeForm'];
var parameters = jsonDoc.serviceResponse.parameters.parameter;
for (i = 0; i < parameters.length; i++) {
if (parameters[i].type === "LISTBOX") {
//Add the label for the parameter to the form
container.appendChild(document.createTextNode(parameters[i].description));
//New Line
var br = document.createElement("br");
container.appendChild(br);
//Obtain the options object
var options = parameters[i].options.option;
var _select = document.createElement('select');
for (j = 0; j < options.length; j++) {
// Add a new check box item
var _input = document.createElement('input');
_input.type = 'checkbox';
_input.value = options[j].value;
container.appendChild(_input);
//Create the label for the check box item
var _text = document.createTextNode(options[j].value);
var p = document.createElement("element");
p.appendChild(_text);
//New line
var br = document.createElement("br");
p.appendChild(br);
container.appendChild(p);
}
}
// We only want to use the parameter if it is of type LOOKUP_CHOICE.
else if (parameters[i].type === "LOOKUP_CHOICE") {
//Create an empty select element. We will append the option
// elements to this element
var _select = document.createElement('select');
//Obtain the options object
var options = parameters[i].options.option;
for (j = 0; j < options.length; j++) {
//Create an option element
var _option = document.createElement('option');
//Set the text node to the display alias in the options object.
var displayNameNode = options[j].displayAlias;
var _text = document.createTextNode(displayNameNode);
//Set the value attribute to the parameter value. This is the value FME
//uses when it runs the translation.
_option.value = options[j].value;
//Append the text to the option and the option to the select tag. We now have something
//that looks like this
//<select>
// <option value="fme_vlaue">Choice with alias value</option>
// ...
//</select>
_option.appendChild(_text);
_select.appendChild(_option);
}
//Append the select elements to the form
container.appendChild(document.createTextNode(parameters[i].description + ' '));
container.appendChild(_select);
//New Line
var br = document.createElement("br");
container.appendChild(br);
}
}
//New Line
var br = document.createElement("br");
container.appendChild(br);
//Create a run button which would be used to submit jobs to FME Server
var _runButton = document.createElement('input');
_runButton.type = "button";
_runButton.value = "Request Data";
_runButton.onclick = runWorkspace;
container.appendChild(_runButton);
}
/**
* Called when the page first loads. Calls FME Server REST API and retrieves the JSON.
*/
function triggerRequestJSONFullForm(){
/*
Commonly available on the web, this function was taken from:
http://ajaxpatterns.org/XMLHttpRequest_Call
*/
function createXMLHttpRequest(){
try {
return new XMLHttpRequest();
}
catch (e) {
}
try {
return new ActiveXObject("Msxml2.XMLHTTP");
}
catch (e) {
}
alert("XMLHttpRequest not supported");
return null;
}
/*
Display the result when complete
*/
function onResponse(){
// 4 indicates a result is ready
if (xhReq.readyState != 4)
return;
// Get the response and display it
parseFullFormJSON(xhReq.responseText);
return;
}
/*
Create the XMLHttpRequest object
*/
var xhReq = createXMLHttpRequest();
// Request Variables
pHostName = "fmeserver.com";
pUrlBase = "http://" + pHostName + "/fmerest/repositories/Samples/austinDownload/parameters.json";
pHttpMethod = "GET";
// Create REST call
pRestCall = pUrlBase +
"?token=d2e728687af92f01207f0b24c61640e9a678944a";
// Send request
xhReq.open(pHttpMethod, pRestCall, true);
xhReq.onreadystatechange = onResponse;
xhReq.send(null);
}
/**
* Called when the user clicks the Run button
*/
function runWorkspace(){
// See code from "Simple Run Workspace - JavaScript" example
alert('Check out the example "Simple Run Workspace - JavaScript" for details on how to submit a job.');
}
</script>
</head>
<body>
<FORM name="fmeForm">
<INPUT type="button" value="Generate Form" name="runButton" onClick="triggerRequestJSONFullForm()">
<br><br>
</FORM>
</body>
</html>