How to add child associations in alfresco webscripts - alfresco

I'm finding it really difficult to find useful documentation on this. Basically I have two custom types 'Concept' and 'ConceptScheme' defined in my alfresco content model. Concept scheme has an association to many child concepts. Like this:
<type name="ancoat:conceptScheme">
<title>Concept Scheme</title>
<parent>ancoat:ddiObject</parent>
<associations>
<child-association name="ancoat:categories">
<source>
<mandatory>true</mandatory>
<many>false</many>
</source>
<target>
<class>ancoat:concept</class>
<mandatory>false</mandatory>
<many>true</many>
</target>
<duplicate>false</duplicate>
<propagateTimestamps>true</propagateTimestamps>
</child-association>
</associations>
<mandatory-aspects>
<aspect>ancoat:describedObject</aspect>
</mandatory-aspects>
</type>
I have two webscripts, one for creating the concept node, and one the concept scheme. I now want to create a webscript which takes some reference to each of those objects, and creates an association between them.
How do I do that? I've found the function Node.createAssociation, but I can't find any examples using it.

I would answer you the java way then.
Let's say that the namespace is http://ancoat.com/model/content/1.0 for the ancoat prefix have this association :
public static final QName ANCOAT_CATEGORIES_ASSOC = QName.createQName("http://ancoat.com/model/content/1.0",
categories);
Then you can associate one node to others with the node service :
getNodeService().setAssociations(pNode, ANCOAT_CATEGORIES_ASSOC, targets);
Where pNode is one node, and targets a list on nodes you want to do the association with.
Now, with a child association, it might be a better way to use the addChild method :
getNodeService().addChild(parentRefs, childRef, assocTypeQName, qname)

Related

Alfresco: How to use ScriptNode processTemplate API without a document?

I'd like to use the Freemarker templating engine from within a controller's webscript to process some expression.
I've seen Alfresco provide the document.processTemplate("template content here") API.
The documentation says: "Executes a template from the repository against the current Document node"
Let's say I don't have any specific document to use, I just want to execute the templating engine and retrieve the output. What's the best way to do it?
Should I use some sort of temporary or "proxy" document? What's the easiest way to do so?
Not quite understandning what you are after here, I however think this is possible (not sure why anyone would like to do it though.)
You write your own class extending the BaseTemplateProcessorExtension, in that class you could write a method performing the stuff you want.
public class MyTemplateProcessorExtension extends BaseTemplateProcessorExtension {
public String myMethod(){
return "Hello World";
}
}
Declare it the following way in your spring config.
<bean id="templateHelper" parent="baseTemplateImplementation" class="my.alfresco.repo.template.TemplateHelper">
<property name="extensionName" value="templateHelper" />
</bean>
Then you can call it from your freemarker with:
${templateHelper.myMethod()}
The freemarker template calling "myMethod" should be a node in the repository (it should be possible to place it in the classpath as well, however I never had any success with this), since the processTemplate needs a nodeRef to the template itself.
Ok, please beware. I don't recommend this approach for anyone :)
I don't think it's possible to not use a document. So use a folder like data dictionary or create a dummy document with no content you always use.
The main purpose of alfresco is managing document.What kind of output you will produce without having value of any metadata of document in the template.This is the main reason behind this is not supported in alfresco, template engine is designed in such a way so that we can process any document.

Override a property and make it Translatable in Doctrine Translatable / Symfony2

I have a mapped-superclass with a string property 'name' which belongs to a bundle (SyliusAssortmentBundle, actually).
I have a class in my bundles that inherits from that mapped-superclass.
I'd like to add Translatable capabilities to my entity by using DoctrineExtensions (Translatable).
Since I cannot redeclare the property 'name' in my mapping, I am trying to override the mapping of that property following this doctrine documentation:
http://docs.doctrine-project.org/en/latest/reference/inheritance-mapping.html#attribute-override
Inspired by this, I added this to my product.orm.xml file
<attribute-overrides>
<attribute-override name="name">
<field name="name" column="name" type="string">
<gedmo:translatable/>
</field>
</attribute-override>
</attribute-overrides>
this doesn't seem to be working. I have added a dummie property (trans_name) to my entity so I am sure that the Translatable Extension is working.
<field name="trans_name" type="string">
<gedmo:translatable/>
</field>
After persisting with something like:
$e->setTranslatableLocale('fr_fr');
$e->setName('name fr');
$e->setTransName('trans name fr');
just the 'trans_name' has been saved to 'ext_translations' table.
So. Is it possible to override the mapping and add Translatable?
If so. What am I doing wrong?...
thanks
As far as I know the #AttributeOverrides, #AssociationOverrides, etc annotations are introduced to override Doctrine's fields and associations. Overriding other annotations (like #Gedmo\Translatable) is not supported.
As alternative you could copy/paste the mappings to your own bundle, add the extra ones you need (like #Gedmo\Translatable) and load these mappings in stead of the ones from SyliusAssortmentBundle.
Suppose problem solved years ago, but I just created pull request in gedmo/doctrine-extensions because just bumped to same problem: https://github.com/Atlantic18/DoctrineExtensions/pull/1631

spring MVC XmlViewResolver configuration

We're wanting to provide alternative PDF views as well as regular JSP views from our controllers and have added a ContentNegotiatingViewResolver and an XmlViewResolver to handle this.
All the examples I've found, including the Spring docs, return a simple view name, which the XmlViewResolver maps to a bean ID in its views.xml file ( in our case, a bean that writes PDF to the HttpResponse).
However we have our jsps organised in subfolders of the location defined in our InternalResourceViewResolver.
E.g.,
<bean id="viewResolver" class= "org.springframework.web.servlet.view.InternalResourceViewResolver" p:order="2">
<property name="viewClass" value="org.springframework.web.servlet.view.JstlView"/>
<property name="prefix" value="/WEB-INF/pages/"/>
<property name="suffix" value=".jsp"/>
</bean>
So, from within our controller we return view names like "a/b/c" for a JSP that is in /WEB-INF/pages/a/b/c.jsp.
This works fine for JSPs, except that you can't have a bean id defined in views.xml as 'a/b/c'; it's not a valid bean ID.
We've investigated several options that either don't work are not satisfactory:
Put all JSPs in a single folder so that we can just use a bean-id-naming-compatible view name that can be resolved by an XmlViewResolver. This works but isn't ideal for organising our JSPs.
Have multiple InternalResourceViewResolver definitions using different prefixes. This just doesn't work; the first resolver of this type does not return null if it fails to find a matching view, it just fails with an exception and subsequent ViewResolvers are not used.
Use a separate controller method (or conditional code in the controller that returns the view name depending on what is the requested content type or URL suffix); these solutions seem to defeat the purpose of keeping a Controller ignorant of its views.
Try using wild-cards in the location property of XmlViewResolver; this fails with an exception.
I'm sure there is a nice elegant solution but it is eluding me just now. Is there a better approach such that I can return a view name like 'a/b/c' which has the potential to be resolved by an XmlViewResolver ?
Thank you for any suggestions.
Richard
Of course, bean aliases are the way to go...after a bit of digging around:
In the views.xml file targetted by XmlViewResolver:
<bean id="PdfView" class="com.blah.PdfDocView" />
<alias name="PdfView" alias="/a/b/structuredDocument"/>
which maps '/a/b/structuredDocument' to the PdfDocView bean.

In spring mvc portlet can one portlet/controller have multiple context.xml files..?

I was asked this question in an interview. I said no then he asked then how do I access other portlet controllers. I am new to spring and what I know is that in application context file we have beans that are nothing but controllers and their corresponding dependencies...which are defined like below:
<bean id="projectProfileSummaryController" class="com.ca.beacon.implproject.controllers.ProjectProfileSummaryController">
<property name="restTemplateBuilder" ref="restTemplateBuilder"/>
<property name="implementProjectService" ref="implementProjectService"/>
along with their views that is defined in view resolver.
Am I right or wrong?
First of all, one portlet can have multiple controller classes.
Second of all, according to docs for FrameworkPortlet (parent class of DispatcherPortlet):
Passes a "contextConfigLocation" portlet init-param to the context instance, parsing it into potentially multiple file paths which can be separated by any number of commas and spaces, like "test-portlet.xml, myPortlet.xml". If not explicitly specified, the context implementation is supposed to build a default location from the namespace of the portlet.
So yes, one portlet can have multiple context xml files.

How Can I Make the XmlIgnore Attribute Method-Specific in a WebService (ASP.Net)?

I understand that I can make the property nullable or use a bool called [PropertyName]Specified to determine whether the property is serialized to XML, but I would like the auto-generated examples to hide these elements in one method's definition, and show them in another. This way the user knows whether they'll be there or not.
For example,
here is what displays now (same for both):
Web Service Method1 Example
...
<Object>
<Column Value="int" xsi:nil="true" />
</Object>
...
Web Service Method2 Example
...
<Object>
<Column Value="int" xsi:nil="true" />
</Object>
...
here is what I want to display:
Web Service Method1 Example
...
<Object>
<Column Value="int" />
</Object>
...
Web Service Method2 Example
...
<Object />
...
Is this even possible without creating different Classes?
No, it's not. You're serializing instances of classes. This is independent of web methods.
The web service infrastructure doesn't fit what you're looking for. In WSDL, an operation uses messages which have parts which are of types which are described in an XML schema. In order for two operations to be the same except for one element (column), they must use messages referring to different types.
Alternatively, you could have one of your methods accept a parameter of a class without the extra column, and have the other use that same parameter, plus a separate parameter which is just the extra column.
Best way, then, is just to have one class inherit the other and add the Column property.

Resources