Alfresco - add item to existing workflow - workflow

I need help with update workflowTask, add file to existing workflow.
My code is:
List<NodeRef> addNodes = new ArrayList<NodeRef>();
addNodes.add(addNodeRef);
Map<QName, List<NodeRef>> nodesAdd = new HashMap<QName, List<NodeRef>>();
nodesAdd.put(WorkflowModel.ASSOC_PACKAGE, addNodes);
workflowService.updateTask(currentTask.getId(), null, nodesAdd, null); //nullpointer
currentTask is not null, is actual task in workflow, where I want add item
addNodes is list actual NodeRef uploaded to alfresco folder
addNodeRef is only one item uploaded to alfresco
Is there any other way an item is added to the already running workflow?
Where's my mistake?
Thanks in advance

You have to add children to the package. Like this:
NodeRef packageNodeRef = ((ActivitiScriptNode)variables.get(bpm_package")).getNodeRef();
QName qname = nodeService.getPrimaryParent(toAddNodeRef).getQName();
QName assocTypeQName = WorkflowModel.ASSOC_PACKAGE_CONTAINS;
nodeService.addChild(packageNodeRef, toAddNodeRef, assocTypeQName, qname);

Related

Alfresco Rule to Remove (unlink) Category from File

In Alfresco users can use rules to link categories to files. There isn't an option to unlink categories from a file.
How do I programmatically remove (unlink) categories from a file without removing the classification aspect?
If a script is required, do you have an example?
I am using Alfresco 7.0 Share/Community version
take a look into the node browser:
Alfresco stores the categories on a node as an array of nodeRefs to the category nodes.
If you want to remove specific category from a node you need to save the array without the nodeRef for that category.
To illustrate that: the following example removes the category /Regions/EUROPE from a given document node:
var categories= document.properties["cm:categories"];
for (var i = 0; i < categories.length; i++) {
var categoryPath = categories[i].displayPath + '/' + categories[i].name;
logger.log(categoryPath);
if (categoryPath == '/categories/General/Regions/EUROPE'){
categories.splice(i, 1)
}
}
document.properties["cm:categories"]= categories;
document.save();

how to create node path similar to the sling job creates

AEM6.2 - I want to create a node hierarchy similar to the sling creates under "/var/eventing/..".
It should be based as "var/eventing/xx/year/month/date/hours/minutes/seconds/milisenconds/<>"
How do you suggest - to create each folder node by iterating the date format "YYYY/MM/dd/hh/mm/ss/SSS" ?
Or is there any other best way ?
You can use ResourceUtil.getOrCreateResource method. Pass the complete path you need and it will create all the sub directories if it does not already exist
String VAR_DATA_ROOT = "/var/eventing";
Date currentDate = new Date();
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("/YYYY/MM/dd/hh/mm/ss/SSS");
String bucketPath = VAR_DATA_ROOT+simpleDateFormat.format(currentDate);
Resource bucketResource = ResourceUtil.getOrCreateResource(resourceResolver,bucketPath,null,null,false);
//save the data under bucketResource
resourceResolver.commit();

How to invoke importwizard from eclipse plugin programmatically

I need to invoke eclipse importwizard from the eclipse plugin project programmatically. i follow the example from , seems not work
https://resheim.net/2010/07/invoking-eclipse-wizard.html
then in my code , it shows wizards array is empty, do i need to register importwizard ? and how?
IWizardDescriptor[] wizards= PlatformUI.getWorkbench().getImportWizardRegistry().getPrimaryWizards();
The import dialog doesn't use 'primary' wizards. You need to know the id of the wizard you want to use and call the wizard registry findWizard method.
The Import Projects wizard id is org.eclipse.ui.wizards.import.ExternalProject so the code would look like:
String id = "org.eclipse.ui.wizards.import.ExternalProject"
IWizardDescriptor descriptor = PlatformUI.getWorkbench().getImportWizardRegistry().findWizard(id);
IWizard wizard = descriptor.createWizard();
WizardDialog wd = new WizardDialog(display.getActiveShell(), wizard);
wd.setTitle(wizard.getWindowTitle());
wd.open();
private void openProject(String projectfolder) throws CoreException {
//TODO: check if project is already created and open, if yes do nothing or just refresh
IProjectDescription description = null;
IProject project = null;
description = ResourcesPlugin.getWorkspace().loadProjectDescription(
new Path(new File(projectfolder).getAbsolutePath()
+ "/.project"));
project = ResourcesPlugin.getWorkspace().getRoot()
.getProject(description.getName());
project.create(description, null);
project.open(null);
}

Get a folder / zip with files in changelist(s) in TFS with complete directory structure

Our team uses TFS to manage workflow in the following flow:
work item -> source control -> changelist -> manual deploy to servers
Is there any way to just get a list of files with complete directory structure for a given changelist? Ideally, I'd like to be able to select multiple changelists and/or work items to get all the changelists associated with a work item, and get a complete directory structure for files in the changelists/work items.
Any suggestions would be appreciated, thanks!
You can probably use the following code snippit to get started
Uri tfsUri = new Uri(#"http://server:8080/tfs");
string serverPath = #"$/Project";
//Connect to the project collection
var projectCollection = TfsTeamProjectCollectionFactory.GetTeamProjectCollection(
tfsUri, new UICredentialsProvider());
//Get the source code control service.
var sourceControl = projectCollection.GetService<VersionControlServer>();
var history = sourceControl.QueryHistory(
serverPath, //Source control path to the item. Like $/Project/Path ...
LatestVersionSpec.Instance, //Search latest version
0, //No unique deletion id.
RecursionType.Full, //Full recursion on the path
null, //All users
new ChangesetVersionSpec("9829"), //From the 7 days ago ...
LatestVersionSpec.Instance, //To the current version ...
Int32.MaxValue, //Include all changes. Can limit the number you get back.
true, //Include details of items, not just metadata.
false //Slot mode is false.
);
//Enumerate of the changesets.
foreach (Changeset changeset in history.OfType<Changeset>().Take(1))
{
foreach (var change in changeset.Changes)
{
change.Item.ServerItem.Dump();
}
}

How do i set a label on an issue using the JIRA SOAP API

Is there a way to set the "Labels" field for a ticket when creating or updating a JIRA ticket using the SOAP API? A search for "label" in the WSDL reveals nothing, and when getting a ticket using the API which I know has labels set, there is no indication in the result that a label exists.
You can update the label of an existing issue using the field id 'labels'. Here is the code I'm using (C#):
public void LabelIssue(string issueKey, string label)
{
RemoteIssue issue = jiraSoapService.getIssue(token, issueKey);
List<RemoteFieldValue> actionParams = new List<RemoteFieldValue>();
RemoteFieldValue labels = new RemoteFieldValue { id = "labels", values = new string[] { label } };
actionParams.Add(labels);
jiraSoapService.updateIssue(token, issue.key, actionParams.ToArray());
}
I'm pretty sure there's no method to do this in JiraSoapService
http://docs.atlassian.com/rpc-jira-plugin/latest/com/atlassian/jira/rpc/soap/JiraSoapService.html
~Matt
Try updating custom field id 10041. I looked forever and I finally found it.
Here is sample code in python:
update_str = [{"id": "customfield_10041", "values":["my_label"]}]
ret = jira_handle.service.updateIssue(auth, key, update_str)
Hope that helps!!