use of org.alfresco.repo.workflow.WorkflowDeployer in project alfresco-repository by Alfresco.
the class MultiTAdminServiceImpl method createTenant.
@Override
public void createTenant(final String tenantDomainIn, final char[] tenantAdminRawPassword, String contentRootPath, final String dbUrl) {
ParameterCheck.mandatory("tenantAdminRawPassword", tenantAdminRawPassword);
final String tenantDomain = getTenantDomain(tenantDomainIn);
// in case this is the 1st tenant
AuthenticationUtil.setMtEnabled(true);
long start = System.currentTimeMillis();
if ((contentRootContainerPath != null) && (!contentRootContainerPath.isEmpty())) {
String defaultContentRoot = null;
if (!contentRootContainerPath.endsWith("/")) {
defaultContentRoot = contentRootContainerPath + "/" + tenantDomain;
} else {
defaultContentRoot = contentRootContainerPath + tenantDomain;
}
if ((contentRootPath != null) && (!contentRootPath.isEmpty())) {
logger.warn("Use default content root path: " + defaultContentRoot + " (ignoring: " + contentRootPath + ")");
}
contentRootPath = defaultContentRoot;
}
initTenant(tenantDomain, contentRootPath, dbUrl);
if ((dbUrl != null) && (trds != null)) {
try {
// note: experimental - currently assumes a bootstrapped DB schema exists for this dbUrl !
trds.addTenantDataSource(tenantDomain, dbUrl);
} catch (SQLException se) {
throw new AlfrescoRuntimeException("Failed to create tenant '" + tenantDomain + "' for dbUrl '" + dbUrl + "'", se);
}
}
try {
// note: runAs would cause auditable property "creator" to be "admin" instead of "System@xxx"
AuthenticationUtil.pushAuthentication();
AuthenticationUtil.setFullyAuthenticatedUser(getSystemUser(tenantDomain));
TenantUtil.runAsSystemTenant(new TenantRunAsWork<Object>() {
public Object doWork() {
dictionaryComponent.init();
if (isTenantDeployer(tenantFileContentStore)) {
TenantDeployer deployer = tenantDeployer(tenantFileContentStore);
deployer.init();
}
// callback
RetryingTransactionCallback<Object> doImportCallback = new RetryingTransactionCallback<Object>() {
public Object execute() throws Throwable {
// create tenant-specific stores
ImporterBootstrap userImporterBootstrap = (ImporterBootstrap) ctx.getBean("userBootstrap-mt");
bootstrapUserTenantStore(userImporterBootstrap, tenantDomain, tenantAdminRawPassword);
ImporterBootstrap systemImporterBootstrap = (ImporterBootstrap) ctx.getBean("systemBootstrap-mt");
bootstrapSystemTenantStore(systemImporterBootstrap, tenantDomain);
// deprecated
ImporterBootstrap versionImporterBootstrap = (ImporterBootstrap) ctx.getBean("versionBootstrap-mt");
bootstrapVersionTenantStore(versionImporterBootstrap, tenantDomain);
ImporterBootstrap version2ImporterBootstrap = (ImporterBootstrap) ctx.getBean("version2Bootstrap-mt");
bootstrapVersionTenantStore(version2ImporterBootstrap, tenantDomain);
ImporterBootstrap spacesArchiveImporterBootstrap = (ImporterBootstrap) ctx.getBean("spacesArchiveBootstrap-mt");
bootstrapSpacesArchiveTenantStore(spacesArchiveImporterBootstrap, tenantDomain);
ImporterBootstrap spacesImporterBootstrap = (ImporterBootstrap) ctx.getBean("spacesBootstrap-mt");
bootstrapSpacesTenantStore(spacesImporterBootstrap, tenantDomain);
thumbnailRegistry.initThumbnailDefinitions();
// bootstrap workflows
for (WorkflowDeployer workflowDeployer : workflowDeployers) {
workflowDeployer.init();
}
// bootstrap modules (if any)
moduleService.startModules();
return null;
}
};
// if not default DB (ie. dbUrl != null) then run in new Spring managed txn (to ensure datasource is switched)
transactionService.getRetryingTransactionHelper().doInTransaction(doImportCallback, transactionService.isReadOnly(), (dbUrl != null));
return null;
}
}, tenantDomain);
} finally {
AuthenticationUtil.popAuthentication();
}
if (logger.isInfoEnabled()) {
logger.info("Tenant created: " + tenantDomain + " in " + (System.currentTimeMillis() - start) + " ms");
}
}
use of org.alfresco.repo.workflow.WorkflowDeployer in project alfresco-repository by Alfresco.
the class CMISTest method testModelAvailability.
/**
* Test for MNT-10537.
*/
@Test
public void testModelAvailability() throws Exception {
final WorkflowDeployer testWorkflowDeployer = new WorkflowDeployer();
// setup dependencies
testWorkflowDeployer.setTransactionService(transactionService);
testWorkflowDeployer.setWorkflowService(workflowService);
testWorkflowDeployer.setWorkflowAdminService(workflowAdminService);
testWorkflowDeployer.setAuthenticationContext(authenticationContext);
testWorkflowDeployer.setDictionaryDAO(dictionaryDAO);
testWorkflowDeployer.setTenantAdminService(tenantAdminService);
testWorkflowDeployer.setTenantService(tenantService);
testWorkflowDeployer.setNodeService(nodeService);
testWorkflowDeployer.setNamespaceService(namespaceService);
testWorkflowDeployer.setSearchService(searchService);
// populate workflow parameters
java.util.Properties props = new java.util.Properties();
props.setProperty(WorkflowDeployer.ENGINE_ID, "activiti");
props.setProperty(WorkflowDeployer.LOCATION, "activiti/testCustomActiviti.bpmn20.xml");
props.setProperty(WorkflowDeployer.MIMETYPE, "text/xml");
props.setProperty(WorkflowDeployer.REDEPLOY, Boolean.FALSE.toString());
List<java.util.Properties> definitions = new ArrayList<java.util.Properties>(1);
definitions.add(props);
testWorkflowDeployer.setWorkflowDefinitions(definitions);
List<String> models = new ArrayList<String>(1);
models.add("activiti/testWorkflowModel.xml");
testWorkflowDeployer.setModels(models);
// deploy test workflow
RetryingTransactionHelper txnHelper = transactionService.getRetryingTransactionHelper();
txnHelper.setForceWritable(true);
txnHelper.doInTransaction(new RetryingTransactionCallback<Object>() {
@Override
public Object execute() throws Throwable {
return AuthenticationUtil.runAs(new RunAsWork<Object>() {
public Object doWork() {
testWorkflowDeployer.init();
return null;
}
}, AuthenticationUtil.getSystemUserName());
}
}, false, true);
org.alfresco.service.cmr.dictionary.TypeDefinition startTaskTypeDefinition = this.dictionaryService.getType(TEST_START_TASK);
org.alfresco.service.cmr.dictionary.TypeDefinition workflowTaskTypeDefinition = this.dictionaryService.getType(TEST_WORKFLOW_TASK);
// check that workflow types were correctly bootstrapped
assertNotNull(startTaskTypeDefinition);
assertNotNull(workflowTaskTypeDefinition);
// caches are refreshed asynchronously
Thread.sleep(5000);
// check that loaded model is available via CMIS API
CallContext context = new SimpleCallContext("admin", "admin", CmisVersion.CMIS_1_1);
CmisService service = factory.getService(context);
try {
List<RepositoryInfo> repositories = service.getRepositoryInfos(null);
assertTrue(repositories.size() > 0);
List<TypeDefinitionContainer> container = service.getTypeDescendants(repositories.get(0).getId(), null, new BigInteger("-1"), true, null);
assertTrue("Workflow model haven't been loaded", container.toString().contains("testwf:startTaskVarScriptAssign"));
} finally {
service.close();
}
}
use of org.alfresco.repo.workflow.WorkflowDeployer in project alfresco-repository by Alfresco.
the class GenericWorkflowPatch method applyInternal.
@Override
protected String applyInternal() throws Exception {
WorkflowDeployer deployer = (WorkflowDeployer) applicationContext.getBean("workflowPatchDeployer");
WorkflowAdminService workflowAdminService = (WorkflowAdminService) applicationContext.getBean("workflowAdminService");
if (workflowDefinitions != null) {
for (Properties props : workflowDefinitions) {
props.put(WorkflowDeployer.REDEPLOY, "true");
}
deployer.setWorkflowDefinitions(workflowDefinitions);
deployer.init();
}
int undeployed = 0;
StringBuilder errorMessages = new StringBuilder();
if (undeployWorkflowNames != null) {
List<String> undeployableWorkflows = new ArrayList<String>(undeployWorkflowNames);
for (String workflowName : undeployWorkflowNames) {
String engineId = BPMEngineRegistry.getEngineId(workflowName);
if (workflowAdminService.isEngineEnabled(engineId)) {
undeployableWorkflows.add(workflowName);
} else {
errorMessages.append(I18NUtil.getMessage(MSG_ERROR_ENGINE_DEACTIVATED, workflowName, engineId));
}
}
undeployed = deployer.undeploy(undeployableWorkflows);
}
// done
StringBuilder msg = new StringBuilder();
if (workflowDefinitions != null) {
msg.append(I18NUtil.getMessage(MSG_DEPLOYED, workflowDefinitions.size()));
}
if (undeployWorkflowNames != null) {
if (msg.length() > 0) {
msg.append(' ');
}
msg.append(I18NUtil.getMessage(MSG_UNDEPLOYED, undeployed));
}
if (errorMessages.length() > 0) {
msg.append(errorMessages);
}
return msg.toString();
}
use of org.alfresco.repo.workflow.WorkflowDeployer in project alfresco-repository by Alfresco.
the class MultiTAdminServiceImpl method importTenant.
/**
* Create tenant by restoring from a complete repository export. This is equivalent to a bootstrap import using restore-context.xml.
*/
@Override
public void importTenant(final String tenantDomainIn, final File directorySource, String contentRoot) {
final String tenantDomain = getTenantDomain(tenantDomainIn);
// in case this is the 1st tenant
AuthenticationUtil.setMtEnabled(true);
initTenant(tenantDomain, contentRoot, null);
try {
// note: runAs would cause auditable property "creator" to be "admin" instead of "System@xxx"
AuthenticationUtil.pushAuthentication();
AuthenticationUtil.setFullyAuthenticatedUser(getSystemUser(tenantDomain));
dictionaryComponent.init();
if (isTenantDeployer(tenantFileContentStore)) {
TenantDeployer deployer = tenantDeployer(tenantFileContentStore);
deployer.init();
}
// import tenant-specific stores
importBootstrapUserTenantStore(tenantDomain, directorySource);
importBootstrapSystemTenantStore(tenantDomain, directorySource);
importBootstrapVersionTenantStore(tenantDomain, directorySource);
importBootstrapSpacesArchiveTenantStore(tenantDomain, directorySource);
importBootstrapSpacesModelsTenantStore(tenantDomain, directorySource);
importBootstrapSpacesTenantStore(tenantDomain, directorySource);
thumbnailRegistry.initThumbnailDefinitions();
// notify listeners that tenant has been created & hence enabled
for (TenantDeployer tenantDeployer : tenantDeployers) {
tenantDeployer.onEnableTenant();
}
// bootstrap workflows, if needed
if (workflowService.isMultiTenantWorkflowDeploymentEnabled()) {
for (WorkflowDeployer workflowDeployer : workflowDeployers) {
workflowDeployer.init();
}
}
// bootstrap modules (if any)
moduleService.startModules();
} finally {
AuthenticationUtil.popAuthentication();
}
if (logger.isInfoEnabled()) {
logger.info("Tenant imported: " + tenantDomain);
}
}
Aggregations