Alfresco APS - Getting process instance name in a script - alfresco

I need to develop a script that change dynamically the Process Instance name (in Alfresco APS 1.9). The change is conditional, like "If the name is 'ABC' then new name = 'ABC 2', else name = 'ABC 3' ".
I've found that to rename the Process Instance I can use the Groovy script below and it works fine:
execution.getEngineServices().getRuntimeService().setProcessInstanceName(execution.getProcessInstanceId(), "ABC 2");
But I need to get the current Process Instance name to check which would be the new name (How to get 'ABC' in my example above).
How can I get the Process Instance name using Groovy?

Try:
execution.getProcessInstance().getName()
Or:
execution.getProcessInstance().getProcessDefinitionName()

Please try the below code snippet to get the Process Instance name.
HistoricProcessInstance historicProcessInstance = historyService.createHistoricProcessInstanceQuery().processInstanceId(processInstance1.getProcessInstanceId()).singleResult();
log.info(historicProcessInstance.getName());

Related

How to read connection string from .net core application which runs set of Nunit test cases

I have an appsettings.json file with the keys. I need to pass this to Nunit tests file.
how to do this?
{
"Mailing": {
"Smtp": {
"mailTo": "xxx#aperture-control.com",
"mailTo": "xxx",
"mailSubject": "Data Validation Report",
"mailBody": "Location Results",
"smtpHost": "xxx",
"smtpPort": "xx",
"smtpUser": "xx#aperture-control.com",
"smtpPassword": "xx",
}
},
"ElasticSettings": {
"ClusterUrl": "xxxx",
"jobIndex": "uklocation",
"host_versions": "uk"
}
}
``
You can pass the name of the file to NUnit as a run parameter.
If you are running with NUnit3-console, use the --testparam option to pass the name of the file. See https://docs.nunit.org/articles/nunit/running-tests/Console-Command-Line.html
If you are using the NUnit3 Visual Studio adapter, you will need to place the argument in a .runsettings file. In this case, each named parameter you wish to pass should be included as a parameter under RunSettings/TestRunParameters/Parameter
Within your test code, you access the value of the parameter using TestContext.TestParameters. One simple approach is to use `TestContext.TestParameters["myparamname"] but other options are shown in the docs at https://docs.nunit.org/articles/nunit/writing-tests/TestContext.html
I haven't told you where in your code to place this, since you haven't indicated exactly how you want to use the information. Since you will need to parse the file, you'll want to put it somewhere where it is only executed once, or a few times. Since the parameter is static, you can save extracted values in a singleton if you like.
UPDATE
The sample test you have shown (in a comment!) gives no extra info about how you are using the test case source. It's unclear whether only one test or many use it and whether variations are needed for different tests. So I'm giving an example that will work for the single test you have shown.
IEnumerable<TestCaseData> MyJSONData()
{
string file = TestContext.TestParameters["mySettingsFile"];
// Read your file and set name, query1 and query2
// Use whatever software you normally use to read it
yield return new TestCaseData(name, query1, query2);
}
[TestCaseSource(nameof(MyJSONData))]
public void MyTestCase(string name, string query1, string query2)
{
// Put your test code here
}
Running under nunit3-console.exe you would specify the option
--testParameter "mySettingsFile=PATH TO YOUR FILE"
You'll have better results with future questions if you provide a full example of code rather than trying to describe it in words.

Symfony: how to customize output of available commands?

We are building a console application using symfony/console (great library by the way). The available commands show up as such:
Available commands:
check-deps Get a report of resolved and missing (if any) dependencies.
gen-docs Rebuild the API / code documentation
help Displays help for a command
list Lists commands
restart Restart the Nginx and PHP-FPM processes.
show-changes Show all local changes to the source code since the last push.
test Run the unit tests
test-coverage Run the unit tests and include a coverage report.
The name of the command shows up in green and the description shows up in white.
Currently, Available commands is the only section. Is there a simple way using OOP to create multiple sections for commands?
Alternatively, is there a way to change the green color for the command label?
You can create a new section by using colon notation.
$this
->setName('newSection:greet') //<--- This line does the trick
->setDescription('Greet someone')
->addArgument(
'name',
InputArgument::OPTIONAL,
'Who do you want to greet?'
)
->addOption(
'yell',
null,
InputOption::VALUE_NONE,
'If set, the task will yell in uppercase letters'
);
However in that case you need to run your command with new section name added as namespace,
> php app.php newSection:greet Avindra.
If you name your section with a whitespace like "New Section" you need to call your command like,
> php app.php "New Section:greet" Avindra.
And this is how you can change the color of info annotation of the application itself.
#!/usr/bin/env php
<?php
require __DIR__.'/vendor/autoload.php';
use Command\GreetCommand;
use Command\HelloCommand;
use Symfony\Component\Console\Application;
use Symfony\Component\Console\Output\ConsoleOutput;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Formatter\OutputFormatter;
use Symfony\Component\Console\Formatter\OutputFormatterStyle;
$application = new Application();
$application->add(new GreetCommand());
$application->add(new HelloCommand());
//Create a new OutputFormatter
$formatter = new OutputFormatter();
//Change info annotation color by blue
$formatter->setStyle('info', new OutputFormatterStyle('blue'));
//Construct output interface with new formatter
$output = new ConsoleOutput(OutputInterface::VERBOSITY_NORMAL, null, $formatter);
//Run your application with your new output interface
$application->run(null, $output);
You can check the related source code for more options here;
https://github.com/symfony/Console/blob/5f241906889f0a3e7b1854b42e7c92a0ea8516ce/Formatter/OutputFormatter.php#L51
https://github.com/symfony/Console/blob/b6b351d326e2fb2fe673a808630f938c2881a473/Formatter/OutputFormatterStyle.php#L21
Hope it helps.

Getting the site name in alfresco email notification

I am trying to notify users whenever a site is created in alfresco share. I created a rule for the site folder in the repository.
In Define Rule, I selected:
When: Items are created or entered in the folder
If all criteria are met: Description contains "a"
Perform Action: Send email
But in the message of the email I need to give the site name.
For example:
A new site named "Sample" is created. Click the link to join the site.
How can I get the site name and corresponding link to join the site?
You can do something like this.
var currentSite = Alfresco.constants.SITE;
var siteObject = siteService.getSite(currentSite );
If you are using javascript directly to send mail you you will have site object available .
You can also try this
siteId = page.url.templateArgs.site;
If you are using ftl you can probably pass sitename from script file to FTL file.
You have multiple options to get current site name depending on the context where you are trying to access it.

Documentum DQL Query

How to create a new dm_document object using document from local system using DQL? I have tried the following but it's not working:
create dm_document object
SET title = 'TEST',
SET subject = 'TRIAL',
set object_name = 'Test123',
SETFILE 'c:\test.txt' with CONTENT_FORMAT= 'msww'
How do you run this DQL?
If you're doing it via Documentum Administrator, Documentum looks for the file with path 'C:\test.txt' on an application server machine wherer DA runs. So if you want to upload it into documentum you must place this file into appserver machine or use another tool for execution DQL.
And could you please show us an error, that you got
Your DQL works for me (!) but after clean any line-warp, so try this
create dm_document object SET title = 'TEST', SET subject = 'TRIAL', set object_name = 'Test123', SETFILE 'c:\test.txt' with CONTENT_FORMAT= 'msww'
...and be sure there is a such file on Content Server (not local) file system
good luck

Drupal - Get image from url and import it into node

Im writing a module for drupal, Im trying to create a node from my module, everything is fine , I only have 1 problem with creating an image , The image exist on different server, so I want to grab the page and insert it , I install module http://drupal.org/project/filefield_sources , which has remote option , I search in the module code , I could not find the function that he used for this process, module work very nice from interface , but how i make it do the job from code ? which function should i call and what parameter should i pass .
I'm over Drupal 6.
Hopefully you're using Drupal 7...
The system_retrieve_file() function will download a file from a remote source, copy it from temp to a specified destination and optionally save it to the file_managed table if you want it to be managed.
$managed = TRUE; // Whether or not to create a Drupal file record
$path = system_retrieve_file($url, 'public://my_files/', $managed);
If you want to get the file object immediately after you've done this, the following is the only way I've found so far:
$file = file_load(db_query('SELECT MAX(fid) FROM {file_managed}')->fetchField());
get fid using $path->fid. no need to mysql

Resources