01-09-2013 08:11 PM
01-11-2013 06:31 AM
<webscript>
<shortname>Create Tenant</shortname>
<description><![CDATA[
Create a tenant.
<br />You must have "administrator" privileges to create a tenant.
<dl>
<dt>tenantDomain</dt> <dd> mandatory </dd>
<dt>tenantAdminPassword</dt> <dd> mandatory </dd>
<dt>tenantContentStoreRoot</dt> <dd> optional </dd>
</dl>
]]>
</description>
<url>/api/tenants</url>
<format default="json">argument</format>
<authentication>admin</authentication>
<transaction>required</transaction>
</webscript>
{
"tenantDomain": "${tenant.tenantDomain}",
"enabled": "${tenant.enabled?string}",
"contentRoot": "${tenant.rootContentStoreDir!""}"
}
package org.changemetoyourorg;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import org.alfresco.repo.tenant.TenantAdminService;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.json.JSONException;
import org.json.JSONObject;
import org.json.JSONTokener;
import org.springframework.extensions.webscripts.Cache;
import org.springframework.extensions.webscripts.DeclarativeWebScript;
import org.springframework.extensions.webscripts.Status;
import org.springframework.extensions.webscripts.WebScriptException;
import org.springframework.extensions.webscripts.WebScriptRequest;
/**
* REST API - create tenant
*
* @author janv
* @since Experimental - not tested or support 🙂
*/
public class TenantPost extends DeclarativeWebScript
{
protected static final Log logger = LogFactory.getLog(TenantPost.class);
protected static final String TENANT_DOMAIN = "tenantDomain";
protected static final String TENANT_ADMIN_PASSWORD = "tenantAdminPassword";
protected static final String TENANT_CONTENT_STORE_ROOT = "tenantContentStoreRoot";
protected TenantAdminService tenantAdminService;
public void setTenantAdminService(TenantAdminService tenantAdminService)
{
this.tenantAdminService = tenantAdminService;
}
@Override
protected Map<String, Object> executeImpl(WebScriptRequest req, Status status, Cache cache)
{
String tenantDomain = null;
String tenantAdminPassword = null;
String contentStoreRoot = null;
try
{
JSONObject json = new JSONObject(new JSONTokener(req.getContent().getContent()));
if (! json.has(TENANT_DOMAIN))
{
throw new WebScriptException(Status.STATUS_BAD_REQUEST, "Could not find required 'tenantDomain' parameter");
}
tenantDomain = json.getString(TENANT_DOMAIN);
if (! json.has(TENANT_ADMIN_PASSWORD))
{
throw new WebScriptException(Status.STATUS_BAD_REQUEST, "Could not find required 'tenantAdminPassword' parameter");
}
tenantAdminPassword = json.getString(TENANT_ADMIN_PASSWORD);
if (json.has(TENANT_CONTENT_STORE_ROOT))
{
contentStoreRoot = json.getString(TENANT_CONTENT_STORE_ROOT);
}
}
catch (IOException iox)
{
throw new WebScriptException(Status.STATUS_BAD_REQUEST, "Could not read content from req.", iox);
}
catch (JSONException je)
{
throw new WebScriptException(Status.STATUS_BAD_REQUEST, "Could not parse JSON from req.", je);
}
tenantAdminService.createTenant(tenantDomain, tenantAdminPassword.toCharArray(), contentStoreRoot);
Map<String, Object> model = new HashMap<String, Object>(0);
return model;
}
}
Tags
Find what you came for
We want to make your experience in Hyland Connect as valuable as possible, so we put together some helpful links.