CmisRuntimeException: nodeRef is a mandatory parameter - alfresco

I am trying to use OpenCMIS to create a content with certain type (we can call it namespace:documenttype)
I got this error:
Exception in thread "main" org.apache.chemistry.opencmis.commons.exceptions.CmisRuntimeException:
nodeRef is a mandatory parameter
I tried to create contents of all parent types for the certain type. They are fine.
namespace:documenttype does not have property or aspect called nodeRef.
The code
ContentStream contentStream = <sessionName>.getObjectFactory().createContentStream(
<documentName>, <bytes>.length, <mimetype>, <input>);
Thanks in advance.

Related

Fetch a component by its tcm id using the core services

I need to fetch a component based on its tcm id using the core services. Please help me which function of core service I can use along with some sample code if possible as well.
Thanks in advance!!
Check the section in the documentation, which you can find here
A basic sample (out of my head, untested ;) ):
ComponentData component = (ComponentData)client.Read(yourComponentId, new ReadOptions());
string title = component.Title;
XElement content = XElement.Parse(component.Content);
The Read method will get you an IdentifiableObjectData object, which you can cast to the needed type if you're sure about what you're supposed to be getting back.
The ReadOptions object will instruct the CoreService how to load the item, for instance, with all Keyword URI's loaded as well using LoadFlags.KeywordXlinks

ErrorBinding Spring portlet MVC

Disclaimer: I wished I had a through understanding before starting working with the framework.
But as it is of now, I'm lacking on that front, and hence the question.
I am working with Spring-Portlet MVC.
I have a flow, where in I take an input on a screen, validate the input, depending upon its result it either render same screen or next screen.
Implementation detail:
I have an action method which takes form backed command object. It checks whether entered input is valid or not. If it is not valid, it populate error message in BindingResult instance it takes as another argument.
We have different render method, to render different screen.
I'm taking command object as an argument in these render method. This command object I'm receiving is same as one passed to action.
Problem:
While rerendering a screen spring-mvc should bind the error message populated in action method. Currently when I take command object as argument in render method spring-mvc is somehow unable to bind that error message. But interesting enough it is able to bind the error message if I don't take command object as argument in render method and rather create a new command object altogether there.
can,some one having better understanding of spring-portlet mvc please explain this behaviour, or tell where I am lacking in understanding.
Regards,
Mawia
EDIT: Just to enrich the below answer: Though I didn't exactly isolated the issue which was causing the said behaviour, but the way I met my requirement was using modelattribute. ModelAttribute can be used either on method or a parameter to a method. It ensures that model will made available to all the call till the view is render(that is my understanding!). So we don't need to take command object as parameter in Render method, just annotate the commandObject parameter in action method with ModelAttribute and then you can get the same object returned from model as suggested in the answer below.
I don't think the command/model object should be an argument/parameter in the render method. I have had the same issue trying to get the validation error messages when command/model is defined as argument in render method signature. I typically have the command/object creation/populate in a separate method, like this:
#ModelAttribute(value="address")
public Address getAddress(#RequestParam Integer id){
Address address = null;
if(id != null){
address = myService.getAddress(id);
}else{
address = new Address();
}
return address;
}
If I still need to access the ModelAttribute/command object from the render method, I typically get it by:
#RenderMapping
public String showAddressPage(ModelMap modelMap){
Address address = modelMap.get("address");
//make any additional changes to address
}
I used this example as reference article

ActivityBuilder.Implementation doesn't include NamespacesForImplementation when serialized

I'm having a problem serializing to xaml a WorkflowService that includes an ActivityBuilder for its Body parameter. The ActivityBuilder contains C# expressions and the serialized WorkflowService doesn't activate because some C# expressions refer to custom types. The actual error is "Type 'SomeTypeIPassToAnArgument' is not defined".
My ActivityBuilder is created from a xaml file which includes a TextExpression.NamespacesForImplementation element. This is missing when the WorkflowService is serialized and it seems this is the cause of the problem.
I found that if I serialize the ActivityBuilder itself, the namespaces are included, but using ActivityBuilder.Implementation fails. Unfortunately, when I build the WorkflowService to serialize I have to use ActivityBuilder.Implementation as its Body parameter. I tried using the TextExpression.SetNamespacesForImplementation method to ensure these were attached to the implementation but that didn't help.
The following snippet shows what I'm trying to do and where it's failing.
var loadedXaml = File.ReadAllText(#"C:\workflow.xaml");
Assert.IsTrue(loadedXaml.Contains("NamespacesForImplementation"));
var xamlReader = new XamlXmlReader(new StringReader(loadedXaml));
var builderReader = ActivityXamlServices.CreateBuilderReader(xamlReader);
var builder = XamlServices.Load(builderReader) as ActivityBuilder;
// namespaces are available in the builder itself
Assert.AreNotEqual(0, TextExpression.GetNamespacesForImplementation(builder).Count);
// when saving, the assert fails because the namespaces aren't serialized
var savedXaml = XamlServices.Save(builder.Implementation);
Assert.IsTrue(savedXaml.Contains("NamespacesForImplementation"));
Any idea why this isn't working, or if there's an alternative approach I could use that would work? Ultimately my aim is to be able to load workflows from xaml and incorporate them in a serialized WorkflowService that I can host in an MVC app using a VirtualPathProvider.
Thanks!
You can't use ActivityBuilder as the body of a WorkflowService, ActivityBuilder is just intended to manipulate an Activity at design time. To convert your ActivityBuilder to an Activity, use ActivityXamlServices.CreateBuilderWriter.
You can leverage XamlServices.Transform to pipe a XamlReader over your ActivityBuilder to the writer you create in ActivityXamlServices.CreateBuilderWriter.

AutoMapper: Action on each element during collection processing?

Is it possible to invoke a method on each object that is being copied from a source to a destination collection using AutoMapper? The destination object has a method called
Decrypt() and I would like it to be called for each CustomerDTO element that is created. The only thing that I can figure out is to perform the mapping conversion and then loop again to invoke the Decrypt() method. I'd appreciate your help with this question.
Thanks,
Mike
IQueryable<CustomerDTO> dtos = AutoMapper.Mapper.Map<IQueryable<CustomerEntity>, IQueryable<CustomerDTO>>((BaseRepository.List));
foreach (var item in dtos)
{
item.Decrypt(Seed);
}
It depends if you are decrypting just a property or the whole object. I wasn't sure based on your question.
If you are just decrypting properties, then I suggest that you look into AutoMapper's Custom Value Resolvers. They allow you to take control when resolving a destination property.
If you need to decrypt the whole object, then I suggest you look into AutoMapper's Custom Type Converters. That gives you complete control over the conversion, though it does sort of take the auto out of AutoMapper.

How do I create and populate a Plone object in the portal_factory?

I need to create an (archetypes) object from a View of a second object (object2 - which is not the parent of the new object). It needs to be prepopulated with data from the Request, and from object2.
The simple solution would seem to be to use "default_method" on the schema fields, and that can work for the data from the Request, but I don't believe I have access to the View from there, and therefore not to object2, either. In any case, one of the fields is a ReferenceField to object2 and I've read that ReferenceField ignores "default_method".
The other option is to create it inside the portal_factory, set its defaults, and then display the Add page, allowing the user to modify the content as required, or to exit without actually creating the object. Perfect, except that, of the multitude of methods available to create an object, (invokeFactory(), _createObjectByType(), _constructInstance() & createObject(), that I know of), only createObject actually leaves the object in the portal_factory - and since it only returns a string (the URL of the object's Add page), won't accept keyword arguments, and doesn't seem to notify any events (certainly not IObjectCreatedEvent), I can't see how to modify that with my data before directing the user to the edit page.
This is the pattern that I recommend when is not possible to use createObject:
_id = self.context.generateUniqueId("Document")
_id = self.context.invokeFactory(type_name=type_name, id=_id)
ob = self.context[_id]
ob.edit(
description = "text...",
subject = ('tag1', 'tag2'),
title = "some title...",
)
ob._renameAfterCreation(check_auto_id=True)
_id = ob.getId()
Doh. Finally figured it out.
createObject doesn't, in any real sense, create an object. It really is just a URL to the creation form.
Call .createObject(), get the URL for the form, attach the values you want as query parameters:
url = folder.createObject(type_name='xxx')
url += ?title=abc&description=def...'
self.request.RESPONSE.redirect(url)
will do it.

Resources