Quantcast
Channel: Alfresco Forums - Other APIs
Viewing all 74 articles
Browse latest View live

How get first children with FTL

$
0
0

I have a performance time problem with a custom webscript that I'm doing.

The webscript only search a node by uuid and return a JSON with some properties of the children of this node, and return the number of the subchilds of them too.

I do this in my js:

function main(){var node =[];
    node = search.findNode("workspace://SpacesStore/"+args["uuid"]);
    model.childResults= node.children;} main();

And on my FTL I do this:

<#macro parseChild objectModel><#assign loop =0/><#list objectModel as child><#if (loop >0)>,</#if>{"ID":"${child.id}","PROP_NAME":"${child.properties["name"]}",<#if child.properties["cf:author"]?exists>"AUTHOR":"${child.properties["cf:author"]}",</#if><#if child.properties["cf:data_cf"]?exists>"PROP_CREATED":"${xmldate(child.properties["cf:date_cf"]?datetime)}",</#if>"TYPE":"${child.type}","NUMBER_CHILDS": ${child.children?size} <#assign loop = loop +1/>}</#list></#macro> <#if (childResults?size >0)>{"nodes":[<@parseChild childResults/>]}<#else>
	Empty</#if>

The problem is... I have over 200 folders on the node, and each one have 30 or 40 subfolders too. And when I do child.children?size the webscript takes a lot of time.

Are there any quickly way to know the number of childs on this 200 folders? child.children takes too long.

If this methos don't exists, I have another possibility. Returns only a parameter that gives me if each of this 200 folders have at least one children. For this, I only need to obtain a children of each one. How can I do this? What method can I apply to each child to obtain the first child or know if this child have a child?

Thank you very much!


Lucene query not working

$
0
0

hi,

I have written one webscript in alfresco for assigning user role on a folder. But the query which i have written for finding the folder is not working. Below is my webscript controller:

/*Set permission to a folder using Alfresco javascript API*/ //search for the folder node using lucene search var folderNode =  search.luceneSearch('+PATH:"/app:company_home/cm:testing/*"  AND TYPE:\"cm:folder" AND @cm\\:name:"test"'); //make sure we only get one nodeif(folderNode.length==1){ //set permission "Contributor" to user with username "anythingalfresco" and group "ANYTHINGALFRESCOGROUP" 
folderNode[0].setPermission("Contributor", user);
folderNode[0].setInheritsPermissions(false);
model.myStatus="Permission was set successfully!";}elseif(folderNode.length==0){//no node was found
model.myStatus="Folder not found";}else{//either greater than two  was found
model.myStatus="Duplicate folder found";}

It is giving me folder not found error. I have test folder inside testing folder but still it is giving mr folder not found error.

Please help me what is wrong in my lucene query or is there something else which is not working.

Regards,
Nancy

Upload form help needed

$
0
0

HI,

I'm running Alfresco Community 5.0.d and am working through the wiki.

I need to upload forms to a location other than comanyhome, which translates to the Repository (upload = companyhome.createFile("upload" + companyhome.children.length + "_" + filename) .

Can anyone please tell me how to upload to a different folder/destination?

Thank you so much in advance!
Frank

5.0.d

RMI JCR Forge Project

$
0
0

Hello All,

For those interest in the RMI adapter for Alfresco's JCR interface implementation, a Alfresco Forge project has been started. Please come and participate, contribute, or even complain :).

Documentation for the project is available at:
http://wiki.alfresco.com/wiki/JCR-RMI_Extension

The Forge project is available at:
http://forge.alfresco.com/projects/jcr-rmi/

-Russ
WEM Practice Director, Rivet Logic

Alfresco support, consulting, and training services.
http://www.rivetlogic.com

http://wiki.alfresco.com - Alfresco Wiki docs
http://wiki.alfresco.com/wiki/Developer_Guide - Alfresco Developer Guide

PHP Library Examples Wanted ...

$
0
0

Hi All,

Over the coming weeks I hope to add some example scripts to the Wiki and PHP library to help make the process of understanding the Alfresco PHP API easier.

If you have any examples you'd be willing to share then this will help speed up this process. I'm looking for anything from the very simple (eg: accessing a property value, uploading content, traversing an association) to more complicated scripts, perhaps with elements of UI. The examples can be code snipits or complete scripts.

Any help will be gratefully received and appropriate credit will be given to those scripts that make it into the documentation/library.

Please feel free to post on this thread with your contributions.

Many thanks,
Roy

Roy Wetherall
Founding Engineer and Records Management Architect

Find me on twitter @rwetherall
Don't forget to say if this post was useful >>>>>

PHP Library status

$
0
0

The PHP library was removed from the alfresco code base some time ago.
http://wiki.alfresco.com/wiki/Alfresco_PHP_API

You can still use it, however a better choice is probably the apache chemistry cmis php interface.

Quoting an important posting from Richard Esplin:
That PHP library is an old project that we released as part of Community Edition and which never made it into our Enterprise product. Rather than letting the code wither and die, we have pushed it into Google Code and are encouraging people to play with it. As far as I know it has not been updated for recent releases, and I would not expect it to work with Alfresco without some effort to fix bugs.

The most common way to work with Alfresco from PHP is to run PHP in its own server, and interact using the CMIS API:

http://chemistry.apache.org/php/phpclient.html

Senior Software Engineer
Alfresco

filtering of documents using lucene

$
0
0

Hi,

I have one web application in which documents of a particular user is exposing from alfresco. Now in my web application i want to provide filtering option to user so that he can filter out document among many documents which are available.

Any any one help me how this can be achieved using lucene or some other technic.

Regards,
Nancy

Document Move triggered by Rule.

$
0
0

All, I have been using the scripts provided by alfresco to create a set of rules / scripts to archive scanned documents into month folders once a particular criteria has been met.

I have managed to cobble a script to 'copy' the files into the archive - creating it if neccessary. But have not yet been able to sort the syntax to 'move' the document.

The copy code I use is:

// find the backup folder - create if not already existsvar currentTime =newDate();var month = currentTime.getMonth()+1;var day = currentTime.getDate();var year = currentTime.getFullYear(); var monthNames =["January","February","March","April","May","June","July","August","September","October","November","December"];  var CurrentDayFolder ="Store -"+ monthNames[month]+" "+ year; var backupFolder = space.childByNamePath(CurrentDayFolder); if(backupFolder ==null&& space.hasPermission("CreateChildren")){// create the folder for the first time
   backupFolder = space.createFolder(CurrentDayFolder);}if(backupFolder !=null&& backupFolder.hasPermission("CreateChildren")){// copy the doc into the backup foldervar copy = document.copy(backupFolder);if(copy !=null){// change the name so we know it's a backupvar backupName ="Backup of "+ copy.name;
      copy.name= backupName;
      copy.save();} // record the time of the backup to a log filevar logFile = backupFolder.childByNamePath("audit.txt");if(logFile ==null){
      logFile = backupFolder.createFile("backuplog.txt");}if(logFile !=null){
      logFile.content+="File: "+ backupName + CurrentDayFolder +"\tDate: "+newDate().toGMTString()+"\tSize: "+ copy.size+"\r\n";}}

and tried the foloowing syntax to build the move

var dest = companyhome.childByNamePath("Sites/psn/documentLibrary/test1");
document.move(dest);

can any one suggest a way to join these together as It appears I am not passing the node reference correct.

I am a code newby.

TIA

Richard

4.2

Spring Web Service integrated into Alfresco

$
0
0

I created Spring Web Service(spring-ws) from existing WSDL file. I am able to expose it and test it with SOAP UI.

Via CMIS this service is able to connect and communicate with Alfresco. So, everything is clear with that solution.

But, I have a problem, if I want to put it inside Alfresco Repo AMP(Maven SDK Alfresco 4.2.f) and deploy together spring-ws and repo amp.

Because, I have to edit web.xml and put inside MessageDispatcherServlet and servlet-mapping.

Is there any elegant solution to extend web.xml? Or, do you have some advice about these solutions?

Thanks.

4.2.f

URGENT: Adding document to Alfresco via SOAP/REST

$
0
0

Can someone point me to a simple Java based examples for adding documents and associated metadata to Alfresco via SOAP and REST API's? Thank you so much.

Missing .bin file after restore, favourites are missing as well

$
0
0

After we did Alfresco restore some random users couldn't login to Alfresco. In the logs for each login attempt there is following stacktrace:

REPO_ 2015-11-1616:46:12,569  ERROR [extensions.webscripts.AbstractRuntime][http-apr-9443-exec-9] Exception from executeScript - redirecting to status template error:10160432 Wrapped Exception (with status template):10166691 Failed to execute script 'classpath*:alfresco/templates/webscripts/org/alfresco/slingshot/documentlibrary/doclist.get.js':10166690 Failed to open stream onto channel:
   accessor: ContentAccessor[ contentUrl=store://2015/7/28/10/17/5f8a8649-9f9e-472b-b6c1-4cc21d28155f.bin, mimetype=text/plain, size=0, encoding=UTF-8, locale=en_US]
org.springframework.extensions.webscripts.WebScriptException:10160432 Wrapped Exception (with status template):10166691 Failed to execute script 'classpath*:alfresco/templates/webscripts/org/alfresco/slingshot/documentlibrary/doclist.get.js':10166690 Failed to open stream onto channel:
   accessor: ContentAccessor[ contentUrl=store://2015/7/28/10/17/5f8a8649-9f9e-472b-b6c1-4cc21d28155f.bin, mimetype=text/plain, size=0, encoding=UTF-8, locale=en_US]
	at org.springframework.extensions.webscripts.AbstractWebScript.createStatusException(AbstractWebScript.java:
	...at java.lang.Thread.run(Thread.java:744)
Caused by: org.alfresco.scripts.ScriptException:10166691 Failed to execute script 'classpath*:alfresco/templates/webscripts/org/alfresco/slingshot/documentlibrary/doclist.get.js':10166690 Failed to open stream onto channel:
   accessor: ContentAccessor[ contentUrl=store://2015/7/28/10/17/5f8a8649-9f9e-472b-b6c1-4cc21d28155f.bin, mimetype=text/plain, size=0, encoding=UTF-8, locale=en_US]
	at org.alfresco.repo.jscript.RhinoScriptProcessor.execute(RhinoScriptProcessor.java:204)
        ...at org.springframework.extensions.webscripts.DeclarativeWebScript.execute(DeclarativeWebScript.java:86)
	... 33 more
Caused by: org.alfresco.service.cmr.repository.ContentIOException:10166690 Failed to open stream onto channel:
   accessor: ContentAccessor[ contentUrl=store://2015/7/28/10/17/5f8a8649-9f9e-472b-b6c1-4cc21d28155f.bin, mimetype=text/plain, size=0, encoding=UTF-8, locale=en_US]
	at org.alfresco.repo.content.AbstractContentReader.getContentInputStream(AbstractContentReader.java:401)
	...	at org.mozilla.javascript.gen.classpath__alfresco_templates_webscripts_org_alfresco_slingshot_documentlibrary_doclist_get_js_6._c_Common_getFavourites_11(classpath*:alfresco/templates/webscripts/org/alfresco/slingshot/documentlibrary/doclist.get.js:666)
	at org.mozilla.javascript.gen.classpath__alfresco_templates_webscripts_org_alfresco_slingshot_documentlibrary_doclist_get_js_6.call(classpath*:alfresco/templates/webscripts/org/alfresco/slingshot/documentlibrary/doclist.get.js)
	at org.mozilla.javascript.optimizer.OptRuntime.callProp0(OptRuntime.java:85)
	at org.mozilla.javascript.gen.classpath__alfresco_templates_webscripts_org_alfresco_slingshot_documentlibrary_doclist_get_js_6._c_getDoclist_20(classpath*:alfresco/templates/webscripts/org/alfresco/slingshot/documentlibrary/doclist.get.js:1111)
	at org.mozilla.javascript.gen.classpath__alfresco_templates_webscripts_org_alfresco_slingshot_documentlibrary_doclist_get_js_6.call(classpath*:alfresco/templates/webscripts/org/alfresco/slingshot/documentlibrary/doclist.get.js)
	at org.mozilla.javascript.optimizer.OptRuntime.callName0(OptRuntime.java:74)
	at org.mozilla.javascript.gen.classpath__alfresco_templates_webscripts_org_alfresco_slingshot_documentlibrary_doclist_get_js_6._c_script_0(classpath*:alfresco/templates/webscripts/org/alfresco/slingshot/documentlibrary/doclist.get.js:1389)
	at org.mozilla.javascript.gen.classpath__alfresco_templates_webscripts_org_alfresco_slingshot_documentlibrary_doclist_get_js_6.call(classpath*:alfresco/templates/webscripts/org/alfresco/slingshot/documentlibrary/doclist.get.js)
	at org.mozilla.javascript.ContextFactory.doTopCall(ContextFactory.java:394)
	at org.mozilla.javascript.ScriptRuntime.doTopCall(ScriptRuntime.java:3091)
	at org.mozilla.javascript.gen.classpath__alfresco_templates_webscripts_org_alfresco_slingshot_documentlibrary_doclist_get_js_6.call(classpath*:alfresco/templates/webscripts/org/alfresco/slingshot/documentlibrary/doclist.get.js)
	at org.mozilla.javascript.gen.classpath__alfresco_templates_webscripts_org_alfresco_slingshot_documentlibrary_doclist_get_js_6.exec(classpath*:alfresco/templates/webscripts/org/alfresco/slingshot/documentlibrary/doclist.get.js)
	at org.alfresco.repo.jscript.RhinoScriptProcessor.executeScriptImpl(RhinoScriptProcessor.java:502)
	at org.alfresco.repo.jscript.RhinoScriptProcessor.execute(RhinoScriptProcessor.java:200)
	... 38 more
Caused by: org.springframework.dao.ConcurrencyFailureException: store://2015/7/28/10/17/5f8a8649-9f9e-472b-b6c1-4cc21d28155f.bin no longer exists
	at org.alfresco.repo.content.EmptyContentReader.getDirectReadableChannel(EmptyContentReader.java:56)
	at org.alfresco.repo.content.AbstractContentReader.getReadableChannel(AbstractContentReader.java:271)
	at org.alfresco.repo.content.AbstractContentReader.getContentInputStream(AbstractContentReader.java:375)
	... 62 more

This part looks interesting:

Caused by: org.springframework.dao.ConcurrencyFailureException: store://2015/7/28/10/17/5f8a8649-9f9e-472b-b6c1-4cc21d28155f.bin no longer exists

If I create this file in the alf_data/contentstore/2015/7/28/10/17/5f8a8649-9f9e-472b-b6c1-4cc21d28155f.bin with empty curly brackets ({}) user can login and it solves the problem. But we have to many users so it would be a total mess to create such file for each user who has this problem.

But in the stacktrace I found another interesting part:

org.mozilla.javascript.gen.classpath__alfresco_templates_webscripts_org_alfresco_slingshot_documentlibrary_doclist_get_js_6._c_Common_getFavourites_11(classpath*:alfresco/templates/webscripts/org/alfresco/slingshot/documentlibrary/doclist.get.js:666)

So I would guess that js method getFavourites in doclist.js is causing this error. Which means that when user logins to Alfresco main page should be shown, but it has dashlet with favorites, which couldn't be loaded due to missing file. This would explain the error.
I also tried to call a preference webscript which returns user preferences (and favourites files as well): https://someco.com/alfresco/service/api/people/someusername/preferences and for some user it failed with exactly the same error:

{"status":{"code":500,"name":"Internal Error","description":"An error inside the HTTP server which prevented it from fulfilling the request."}, "message":"org.alfresco.service.cmr.repository.ContentIOException: 10166868 Failed to open stream onto channel: \n   accessor: ContentAccessor[ contentUrl=store:\/\/2015\/7\/28\/11\/18\/71f8a94e-2fbb-4ec1-a12a-56b8330ebd3c.bin, mimetype=text\/plain, size=0, encoding=UTF-8, locale=en_US]","exception":"", "callstack":[ ], "server":"Community v5.0.0 (c r91299-b145) schema 8,009","time":"Nov 16, 2015 6:28:40 PM"}

So I think that my guess with favourites was right: for some reason after restore all files in the contentstore which contained users' favourites disappeared.

Now reasonable question is how it could be possible?
Because apart from this problem Alfresco works fine, we have more than 60000 documents there and none of them are missed.

And another question: how it could be solved?
As a workaround I think could be useful to get list of all users who used favourites functionality, so we can tell which users will have similar problem with login.

5.0.c

Command servlet in 5.0.2

$
0
0

Hi all,

I'm trying to use the command servlet to execute database scripts in Alfresco 5.0.2 like so:

http://localhost:8080/alfresco/command/script/execute/workspace/SpacesStore/dcf5c20c-5bef-411c-95f0-5fcae72ea25b

However, this functionality seems to have disappeared in Alfresco 5. The wiki doesn't seem to reflect this, nor can I find information in the forums about this change:

https://wiki.alfresco.com/wiki/URL_Addressability#CommandServlet

Does anyone know how I can access this functionality in Alfresco 5?

Thanks a million for your help.

Best regards,
Matthew

5.0

Search site via REST API

$
0
0

Hello,

I would like to have name-based sites in Alfresco. Site names should be like MySite,MySite-One,MySite-Two,MySite-Three etc.. I want to use REST API where I can search for such sites. Example use case: I want to get a site whose name is MySite or MySite-*.

Is there any REST API interface in Alfresco I can use for that?

There is only one I found(and it uses OpenSearch):

Alfresco keyword search (OpenSearch enabled)
GET /alfresco/s/api/search/keyword.html?q={searchTerms}&p={startPage?}&c={count?}&l={language?}
GET /alfresco/s/search/keyword.html?q={searchTerms}&p={startPage?}&c={count?}&l={language?}
GET /alfresco/s/api/search/keyword.atom?q={searchTerms}&p={startPage?}&c={count?}&l={language?}
GET /alfresco/s/search/keyword.atom?q={searchTerms}&p={startPage?}&c={count?}&l={language?}
GET /alfresco/s/api/search/keyword.rss?q={searchTerms}&p={startPage?}&c={count?}&l={language?}
GET /alfresco/s/search/keyword.rss?q={searchTerms}&p={startPage?}&c={count?}&l={language?}
GET /alfresco/s/api/search/keyword.portlet?q={searchTerms}&p={startPage?}&c={count?}&l={language?}

Thanks to poor Alfresco documentation I did not find any website or forum with example of searchTerm or complete request. It also does not return JSON which is another disadvantage.

Can someone help me?

Thanks

Roman

5.0.d

Unit testing org.alfresco.repo.jscript.People.getPeople()

$
0
0

Hi Experts,

I am trying to do unit testing  org.alfresco.repo.jscript.People.getPeople(String) method but I am getting, null pointer exception.

java.lang.NullPointerException
at org.alfresco.repo.jscript.People.getPeoplePaging(People.java:572)
at org.alfresco.repo.jscript.People.getPeople(People.java:559)
at org.alfresco.repo.jscript.People.getPeople(People.java:539)
at org.alfresco.repo.jscript.People.getPeople(People.java:522)
at org.alfresco.repo.jscript.PeopleTest.testGetPeople(PeopleTest.java:110)
at sun.reflect.NativeMethodAccessorImpl.invoke0(NativeMethod)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at junit.framework.TestCase.runTest(TestCase.java:176)
at junit.framework.TestCase.runBare(TestCase.java:141)
at junit.framework.TestResult$1.protect(TestResult.java:122)
at junit.framework.TestResult.runProtected(TestResult.java:142)
at junit.framework.TestResult.run(TestResult.java:125)
at junit.framework.TestCase.run(TestCase.java:129)
at junit.framework.TestSuite.runTest(TestSuite.java:255)
at junit.framework.TestSuite.run(TestSuite.java:250)
at org.junit.internal.runners.JUnit38ClassRunner.run(JUnit38ClassRunner.java:84)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:459)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:675)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:382)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192)

After debugging I found that, "Context" is null during unit testing in  org.alfresco.repo.jscript.People.getPeoplePaging(String, ScriptPagingDetails, String, Boolean) .

Can you please guide me, how I can do the unit testing  org.alfresco.repo.jscript.People.getPeople(String) method?

Thanks,
Murali

Thanks,
Murali

If this post was helpful, please click on "Mark Comment as Useful" !
Blog: www.codingfreaks.net
Community: www.meetup.com/Alfresco-Bangalore-Community
Working for : www.quanticate.com

What is where_id parameter on CMLAddAspect?

$
0
0

Hi,

I'm adding custom aspects throw java webservice client, doing something like this:

NamedValue[] customProps =new NamedValue[2];
customProps[0]= Utils.createNamedValue("{example}AAA","111");
customProps[1]= Utils.createNamedValue("{example}BBB","222");
CMLAddAspect addCustomAspect1 =new CMLAddAspect("{example}my_aspect1", customProps,null,"1"); 
NamedValue[] customProps2 =new NamedValue[1];
customProps2 [0]= Utils.createNamedValue("{example}CCC","333");
CMLAddAspect addCustomAspect2 =new CMLAddAspect("{example}my_aspect2", customProps2 ,null,"2"); 
cml.setAddAspect(new CMLAddAspect[]{ addCustomAspect1 , addCustomAspect2 });

My question is... What means the last parameter of CMLAddAspect? The API say that is a String where_id. On examples I allways see null or "1". But if I add various aspects, I need to put "1" and "2" to specify what is what? Better always "1"? Or whats means?

Thanks a lot!

4.2.e


Default missing parameters in context

$
0
0

I have a timed job that sets its quarrtz cron string using a parameter like this

<property name="cronExpression"><value>${myservice.cron}</value></property>

I would like to be able to default the service cron should someone not set the parameter myservice.cron in alfresco-global.properties and I cannot find out how to do this.

At first I thought this was Freemarker but

${(myservice.cron)!'0 0/1 * * * ?'}

did not work.

Then I found an article saying Freemaker directives must be escaped so I tried

\$\{(myservice.cron)!'0 0/1 * * * ?'\}

but that didn't work either.

More ferreting around on the internet suggests that Alfresco "works out" how to process a parameter based on regex & an array of processors but I cannot fathom out how that works.

Grepping the entire context xml files in Alfresco did not yield any suggestions as to how this can be done

Any kind soul want to explain to me how I set a parameter string that says Use this value if the property exists and if not us "0 0/1 * * * ?"?

Many thanks

Good luck

Bob Johnson

P.S. If this was useful, please mark it as such - it might help someone else to.

Execute script on folder

$
0
0

Hi all!

I need some help to create a script that executes when something goes inside a foler. That seems pretty easy.

But the script needs to make a HTTP Request to a url.

I've been trying with XMLHTTPRequest, connector("alfresco") and Alfresco.Utils.Ajax.request()

But with no success :C , everything I try is "not defined" :/

I dont know if thats the best way to do it, but basically, I just need to send a HTTP Request to other domain when something enters the folder.

Hope someone can help me get a solution :D or point me in the right direction.

Im on Alfresco 5.0d.

Thanks in advance!

5.0.d

Set folder permission restful API

$
0
0

Hi all,

I would know if is there a way to set folder permission via restful api in php. I have a piece of code in my php class to create a new folder in the repository, I would set permission for a specified alfresco group, is it possible?

Thanks

5.0.d

Dynamic Image resizing through API

$
0
0

HI,

Am newbie to Alfresco community. I need some help in
* dynamic image resizing through API, is it possible? if so means please guide me to the correct API.
* I read that we can do the image resizing through Imagemagick also, can u guide me how to do the same using Imagemagick . i have downloaded and installed IMagemagick software and its working fine, i have converted the png to jpg file using command prompt. can someone help me in configuring with the alfresco community version in detail.

Any kind of suggestions would be great help.

Thanks in advance.

How can use service task using java delegates my workflow

$
0
0

I am new to alfresco i am using alfresco5.1.x community edition i am creating workflow in that how can using service task using java delegates please help me

Regards
John

5.1.x
Viewing all 74 articles
Browse latest View live