First of all, I am running V4.2.e Community Edition.
I have the following webscript/free marker template(ftl) to retrieve aspects from a certain node,
[
<#list node.aspects as aspect>
${jsonUtils.toJSONString(aspect)}<#if aspect_has_next>, </#if>
</#list>
]
with the following js part:
var docid = url.extension;
model.node = search.findNode(docid);
It works perfectly. It returns something like:
[
"http://www.alfresco.org/model/content/1.0}titled"
]
but I want:
[
"cm:titled"
]
In the following ScriptNode API I found a similar function called "getAspectsShort":Alfresco Community 4.2 Documentation - Script Node
Obviously there are backend functions in the java classes:
ScriptNode.java
My tried to use it in the following way:
[
<#list node.getAspectsShort as aspect>
${jsonUtils.toJSONString(aspect)}<#if aspect_has_next>, </#if>
</#list>
]
and found the following message in the catalina.out:
Caused by: org.alfresco.service.cmr.repository.TemplateException: 011933961 Fehler bei der Verarbeitung der Mustervorlage 'Expression node.getAspectsShort is undefined on line 2, column 12 in aspe
ct.get.json.ftl.'. Bitte wenden Sie sich an Ihren Systemadministrator.
at org.alfresco.repo.template.FreeMarkerProcessor.process(FreeMarkerProcessor.java:222)
at org.springframework.extensions.webscripts.AbstractWebScript.renderTemplate(AbstractWebScript.java:896)
at org.springframework.extensions.webscripts.DeclarativeWebScript.renderFormatTemplate(DeclarativeWebScript.java:267)
at org.springframework.extensions.webscripts.DeclarativeWebScript.execute(DeclarativeWebScript.java:147)
... 28 more
Caused by: freemarker.core.InvalidReferenceException: Expression node.getAspectsShort is undefined on line 2, column 12 in aspect.get.json.ftl.
at freemarker.core.TemplateObject.assertNonNull(TemplateObject.java:125)
at freemarker.core.IteratorBlock.accept(IteratorBlock.java:100)
at freemarker.core.Environment.visit(Environment.java:221)
at freemarker.core.MixedContent.accept(MixedContent.java:92)
at freemarker.core.Environment.visit(Environment.java:221)
at freemarker.core.Environment.process(Environment.java:199)
at org.alfresco.repo.template.FreeMarkerProcessor.process(FreeMarkerProcessor.java:218)
... 31 more
Any help will be appreciated,
Oliver
Hi you're referring to the JavaScript API but you're using the Freemarker objects to retrieve data. So not all the JavaScript methods are implemented in Freemarker.
So use the node.aspectsShort in your JavaScript controller and pass the value to the model object to the Freemarker template.
Here is the reference wiki of the Template node API
And the reference in the docs
You can use shortQName
${shortQName(jsonUtils.toJSONString(aspect))}
http://docs.alfresco.com/4.0/index.jsp?topic=%2Fcom.alfresco.enterprise.doc%2Freferences%2FAPI-JS-Utility-shortQName.html
Related
I'm using ArangoDB 3.4.2 and I have a weird problem that I'm not able to explain...
I create a graph (myGraph) in the following in arangosh:
var graph_module = require('#arangodb/general-graph');
var myGraph = graph_module._create('mygraph');
myGraph._addVertexCollection('vertexes');
var edges = graph_module._relation('edges', ['vertexes'], ['vertexes']);
myGraph._extendEdgeDefinitions(edges);
Being vertexes and edges the collections for vertexes and edges, respectively.
Now, I create two vertexes:
db.vertexes.save({"name": "A", "_key": "A"});
db.vertexes.save({"name": "B", "_key": "B"});
So far so good. But now I try to create the edge between both and I get a fail:
127.0.0.1:8529#myDB> db.edges.save("vertexes/A", "vertexes/B", {"name": "A-to-B"});
JavaScript exception: TypeError: Cannot read property 'save' of undefined
!db.edges.save("vertexes/A", "vertexes/B", {"name": "A-to-B"});
! ^
stacktrace: TypeError: Cannot read property 'save' of undefined
at <shell command>:1:9
It seems that db.edges is undefined:
127.0.0.1:8529#MyDB> console.log(db.edges)
2019-01-26T19:01:52Z [98311] INFO undefined
But now, if I run db._collections() it seems that db.edges gets defined (weird!)
127.0.0.1:8529#MyDB> db._collections()
...
127.0.0.1:8529#MyDB> console.log(db.edges)
2019-01-26T19:02:58Z [98311] INFO [ArangoCollection 16807, "edges" (type edge, status loaded)]
and in this moment, the db.edges.save(...) operation works:
127.0.0.1:8529#MyDB> db.edges.save("vertexes/A", "vertexes/B", {"name": "A-to-B"});
{
"_id" : "edges/16899",
"_key" : "16899",
"_rev" : "_YGsKKq2--_"
}
Why db.edges is undefined at the first save()? Why a show colletions operation (which I understand is read-only) is getting it defined? Maybe I'm doing something wrong?
When executing db.edges.save() an internal cache is accessed. If this cache is clear, executing db.edges.save() works to save an edge. Since db._collections() resets this cache, it is possible to run the command afterwards. However if this cache is not clear, an error is thrown as you observed.
The correct and safe way is to access the collection via db._collection("collection-name").
Therefore you can use the following command to save an edge in the edges collection:
db._collection("edges").save("vertexes/A", "vertexes/B", {"name": "A-to-B"});
I have searched online but can't find why or how to fix it.
Problem:
My JUnit test pulls a list of user id's from a REST-API.
However, I can't seem to assert the contents of the response...
API Response:
[
{"userId":1458548702},
{"userId":1458548703},
{"userId":1458548704},
{"userId":1458548706},
{"userId":1458548707}
]
Assertion Code:
List<Integer> expectedIds = ....
ResultActions result = ...
//JSONArray and expectedIds are the same length
result.andExpect(
MockMvcResultMatchers.jsonPath(
"$.*",
Matchers.hasSize(expectedIds.size())
)
);
//Below Fails:
result.andExpect(
MockMvcResultMatchers.jsonPath(
"$[*].userId",
Matchers.containsInAnyOrder(expectedIds)
)
);
Error Message:
java.lang.AssertionError: JSON path "$[*].userId"
Expected: iterable over [<[1458548702, 1458548703, 1458548704, 1458548706, 1458548707]>] in any order
but: Not matched: <1458548702>
at org.hamcrest.MatcherAssert.assertThat(MatcherAssert.java:20)
...
Libraries I'm using:
com.jayway.jsonpath json-path 2.0.0
com.jayway.jsonpath json-path-assert 2.0.0
org.mockito mockito-core 1.10.19
org.hamcrest hamcrest-all 1.3
Doctrine query builder allows me to concat two fields only.
class Expr {
// ...
public function concat($x, $y); // Returns Expr\Func
To concatenate 3 fields I use:
$qb->expr()->concat(
'table.field1',
$qb->expr()->concat('table.field2', 'table.field3')
);
And the SQL will be:
CONCAT('table.field1', CONCAT('table.field2', 'table.field3'))
How to get one concat?
When I try to call directly
new Expr\Func('CONCAT', array('table.field1', 'table.field2', 'table.field3'));
Executing query gives me an error
[Syntax Error] line 0, col 237: Error: Expected Doctrine\ORM\Query\Lexer::T_CLOSE_PARENTHESIS, got ','
Dumping DQL:
CONCAT('table.field1', 'table.field2', 'table.field3')
Dumping SQL using $qb->getQuery()->getSQL():
[Syntax Error] line 0, col 237: Error: Expected Doctrine\ORM\Query\Lexer::T_CLOSE_PARENTHESIS, got ','
CONCAT with variable number of arguments has been introduced in Doctrine ORM version 2.4.0, so you are probably using an older version. I've tested a similar DQL in my project and works as expected.
You should upgrade your Doctrine ORM deps with:
php composer.phar require doctrine/orm:~2.4
Note that (for now) variable arguments are supported only by Expr\Func constructor, but is not supported in Expr::concat method; you still need this syntax:
new Expr\Func('CONCAT', array('table.field1', 'table.field2', 'table.field3'));
UPDATE I've created a PR on GitHub to support multiple arguments in Expr::concat
I'm creating a workflow databroker, and in the pre-workflow I am using a dataset-proxy to iterate over the populate-dataset. However I get the following error when I compile:
XMLCommand.initialize failed: java.lang.NullPointerException
at nz.co.aviarc.xml.command.dataset.DatasetProxy.initialize(DatasetProxy.java:35)
at com.aviarc.framework.xml.command.XMLCommandElementImpl.finalize(XMLCommandElementImpl.java:90)
at com.aviarc.framework.xml.compilation.XMLSAXHandler.endElement(XMLSAXHandler.java:336)
at net.sf.saxon.event.ContentHandlerProxy.endElement(ContentHandlerProxy.java:391)
at net.sf.saxon.event.NamespaceReducer.endElement(NamespaceReducer.java:213)
at net.sf.saxon.event.ReceivingContentHandler.endElement(ReceivingContentHandler.java:443)
at org.apache.xerces.parsers.AbstractSAXParser.endElement(AbstractSAXParser.java:598)
at org.apache.xerces.impl.XMLNSDocumentScannerImpl.scanEndElement(XMLNSDocumentScannerImpl.java:673)
at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl$FragmentContentDispatcher.dispatch(XMLDocumentFragmentScannerImpl.java:1645)
at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanDocument(XMLDocumentFragmentScannerImpl.java:324)
at org.apache.xerces.parsers.XML11Configuration.parse(XML11Configuration.java:875)
at org.apache.xerces.parsers.XML11Configuration.parse(XML11Configuration.java:798)
at org.apache.xerces.parsers.XMLParser.parse(XMLParser.java:108)
at org.apache.xerces.parsers.AbstractSAXParser.parse(AbstractSAXParser.java:1198)
at org.apache.xerces.jaxp.SAXParserImpl$JAXPSAXParser.parse(SAXParserImpl.java:564)
at net.sf.saxon.event.Sender.sendSAXSource(Sender.java:404)
at net.sf.saxon.event.Sender.send(Sender.java:193)
at net.sf.saxon.IdentityTransformer.transform(IdentityTransformer.java:30)
at com.aviarc.framework.xml.compilation.AviarcXMLResourceCompiler.compile(AviarcXMLResourceCompiler.java:137)
...
I get exactly the same error even when I use the code example straight out of the documentation (com.aviarc.dataset:1.1.0):
<workflow xmlns:ds="urn:aviarc:xmlcommand:com.aviarc.dataset">
<ds:dataset-proxy dataset="ds" proxyname="dsproxy">
<set-current-row dataset="dsproxy" position="2" />
<set-field field="dsproxy.email" value="test#test.com" />
</ds:dataset-proxy>
</workflow>
Turns out that the documentation is wrong, as proxyname is not a valid attribute on dataset-proxy. I didn't see it at first (because of the huge stack trace) but I was also getting this warning:
Unknown attribute 'proxyname'
The correct attribute is name, not proxyname. Changing this resolved the error.
I have created Json response file in Company Home > Data Dictionary >
Web Scripts > org > alfresco > sample with the Name:
folder.get.json.ftl for one of the Alfresco Web
Script(http:// localhost:8080/alfresco/service/sample/folder/Company%20Home)according
to the guidelines mentioned in
http://docs.alfresco.com/4.0/index.jsp?topic=%2Fcom.alfresco.enterprise.doc%2Ftasks%2Fws-json-add.html.
After successful addition of the webscript , i have refresh the
Webscripts.
Now when im tring to call this websrcipt using the URL
http:// localhost:8080/alfresco/service/sample/folder/Company%20Home?format=json
i am getting Internal Error(500).
Please help me out regarding this.
Thanks in Advance!!!!
Below is the stack trace
{
"status" :
{
"code" : 500,
"name" : "Internal Error",
"description" : "An error inside the HTTP server which prevented it from fulfilling the request."
},
"message" : "01270141 Wrapped Exception (with status template): 01270216 Error during processing of the template 'Expression verbose is undefined on line 12, column 14 in org\/alfresco\/sample\/folder.get.json.ftl.'. Please contact your system administrator.",
"exception" : "org.springframework.extensions.webscripts.WebScriptException - 01270141 Wrapped Exception (with status template): 01270216 Error during processing of the template 'Expression verbose is undefined on line 12, column 14 in org\/alfresco\/sample\/folder.get.json.ftl.'. Please contact your system administrator.",
"callstack" :
[
"" ,"freemarker.core.InvalidReferenceException: Expression verbose is undefined on line 12, column 14 in org\/alfresco\/sample\/folder.get.json.ftl."
,"freemarker.core.TemplateObject.assertNonNull(TemplateObject.java:125)"
,"freemarker.core.Expression.isTrue(Expression.java:145)"
,"freemarker.core.ConditionalBlock.accept(ConditionalBlock.java:77)"
,"freemarker.core.Environment.visit(Environment.java:221)"
,"freemarker.core.MixedContent.accept(MixedContent.java:92)"
,"freemarker.core.Environment.visit(Environment.java:221)"
,"freemarker.core.IteratorBlock$Context.runLoop(IteratorBlock.java:179)"
,"freemarker.core.Environment.visit(Environment.java:428)"
,"freemarker.core.IteratorBlock.accept(IteratorBlock.java:102)"
,"freemarker.core.Environment.visit(Environment.java:221)"
,"freemarker.core.MixedContent.accept(MixedContent.java:92)"
,"freemarker.core.Environment.visit(Environment.java:221)"
,"freemarker.core.Environment.process(Environment.java:199)"
,"org.alfresco.repo.template.FreeMarkerProcessor.process(FreeMarkerProcessor.java:202)"
,"org.springframework.extensions.webscripts.AbstractWebScript.renderTemplate(AbstractWebScript.java:714)"
,"org.springframework.extensions.webscripts.DeclarativeWebScript.renderFormatTemplate(DeclarativeWebScript.java:267)"
,"org.springframework.extensions.webscripts.DeclarativeWebScript.execute(DeclarativeWebScript.java:147)"
,"org.alfresco.repo.web.scripts.RepositoryContainer$2.execute(RepositoryContainer.java:400)"
,"org.alfresco.repo.transaction.RetryingTransactionHelper.doInTransaction(RetryingTransactionHelper.java:388)"
,"org.alfresco.repo.web.scripts.RepositoryContainer.transactionedExecute(RepositoryContainer.java:453)"
,"org.alfresco.repo.web.scripts.RepositoryContainer.transactionedExecuteAs(RepositoryContainer.java:491)"
,"org.alfresco.repo.web.scripts.RepositoryContainer.executeScript(RepositoryContainer.java:316)"
,"org.springframework.extensions.webscripts.AbstractRuntime.executeScript(AbstractRuntime.java:352)"
,"org.springframework.extensions.webscripts.AbstractRuntime.executeScript(AbstractRuntime.java:189)"
,"org.springframework.extensions.webscripts.servlet.WebScriptServlet.service(WebScriptServlet.java:118)"
,"javax.servlet.http.HttpServlet.service(HttpServlet.java:717)"
,"org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)"
,"org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)"
,"org.alfresco.web.app.servlet.GlobalLocalizationFilter.doFilter(GlobalLocalizationFilter.java:58)"
,"org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)"
,"org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)"
,"org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)"
,"org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)"
,"org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:465)"
,"org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)"
,"org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)"
,"org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)"
,"org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:298)"
,"org.apache.coyote.http11.Http11AprProcessor.process(Http11AprProcessor.java:859)"
,"org.apache.coyote.http11.Http11AprProtocol$Http11ConnectionHandler.process(Http11AprProtocol.java:579)"
,"org.apache.tomcat.util.net.AprEndpoint$Worker.run(AprEndpoint.java:1555)"
,"java.lang.Thread.run(Thread.java:619)"
,"org.alfresco.service.cmr.repository.TemplateException: 01270216 Error during processing of the template 'Expression verbose is undefined on line 12, column 14 in org\/alfresco\/sample\/folder.get.json.ftl.'. Please contact your system administrator."
,"org.alfresco.repo.template.FreeMarkerProcessor.process(FreeMarkerProcessor.java:206)"
,"org.springframework.extensions.webscripts.WebScriptException: 01270141 Wrapped Exception (with status template): 01270216 Error during processing of the template 'Expression verbose is undefined on line 12, column 14 in org\/alfresco\/sample\/folder.get.json.ftl.'. Please contact your system administrator."
,"org.springframework.extensions.webscripts.AbstractWebScript.createStatusException(AbstractWebScript.java:884)"
],
"server" : "Community v4.0.0 (a r30055) schema 5,016",
"time" : "Feb 27, 2012 9:53:23 AM"
}
The key line is:
freemarker.core.InvalidReferenceException: Expression verbose is undefined on line 12, column 14 in org/alfresco/sample/folder.get.json.ftl.
Your template, on line 12, character 14, you've referenced a variable "verbose" which doesn't exist. You should either set that variable in the model, or check if it's defined or not before using it.