Powered By Blogger

Friday, October 28, 2011

Liferay and Alfresco Doclib integration

Alfresco uses org.springframework.extensions.webscripts.connector.HttpConnector to talk with
Alfresco. This has the hardcoded value
headers.put("X-Alfresco-Remote-User", user);

Since it is hardcoded,if we change the value of th eheader then the authentication will not be respected.

So change the code to fir the your custom external key CTUSER defined in your external file.






alfresco-noauth
Alfresco - unauthenticated access
Access to Alfresco Repository WebScripts that do not require authentication
alfresco
http://localhost:8080/alfresco/s
none



alfresco-feed
Alfresco Feed
Alfresco Feed - supports basic HTTP authentication
http
http://localhost:8080/alfresco/s
true
user



alfrescoCookie
Alfresco Connector
Connects to an Alfresco instance using cookie-based authentication
org.springframework.extensions.webscripts.connector.AlfrescoConnector



alfresco
Alfresco - user access
Access to Alfresco Repository WebScripts that require user authentication
alfrescoCookie
http://localhost:8080/alfresco/wcs
user
true





Thursday, October 27, 2011

Finding the pid of the server running in alfresco

halfwd01:#cd /opt/alfresco/
halfwd01:#find . -name '*.pid'
./tomcat/temp/catalina.pid
halfwd01:#cat ./tomcat/temp/catalina.pid
16789
halfd01:#ps -elf|grep java
0 S patil 14735 14413 0 77 0 - 15296 - 12:24 pts/3 00:00:00 grep java
0 S alfresco 16789 1 5 84 0 - 522368 futex_ Oct26 ? 01:15:21 /opt/alfresco/java/bin/java -Djava.util.logging.config.file=/opt/alfresco/tomcat/conf/logging.properties -Xms512m -Xmx1024m -Xss1024k -XX:MaxPermSize=256m -XX:NewSize=256m -XX:+UseConcMarkSweepGC -Dalfresco.home=/opt/alfresco -Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.ssl=false -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager -Djava.endorsed.dirs=/opt/alfresco/tomcat/endorsed -classpath /opt/alfresco/tomcat/bin/bootstrap.jar -Dcatalina.base=/opt/alfresco/tomcat -Dcatalina.home=/opt/alfresco/tomcat -Djava.io.tmpdir=/opt/alfresco/tomcat/temp org.apache.catalina.startup.Bootstrap start
halfd01:#

Thursday, October 20, 2011

ldap sync in Alfresco





org.alfresco.repo.security.sync.UserRegistrySynchronizerJob







${synchronization.synchronizeChangesOnly}






${synchronization.import.cron}








From here it calls




ChainingUserRegistrySynchronizer.java has a method by name


syncWithPlugin

private void syncWithPlugin(final String zone, UserRegistry userRegistry, boolean forceUpdate,
boolean allowDeletions, boolean splitTxns, final Set visitedZoneIds, final Set allZoneIds)



It has

final BatchProcessor personProcessor = new BatchProcessor(zone
+ " User Creation and Association", this.transactionService.getRetryingTransactionHelper(),
userRegistry.getPersons(lastModified), this.workerThreads, 10, this.applicationEventPublisher,

userRegistry.getPersons(lastModified)


It calls LDAPUSerRegistry

/*
* (non-Javadoc)
* @see org.alfresco.repo.security.sync.UserRegistry#getPersons(java.util.Date)
*/
public Collection getPersons(Date modifiedSince)
{
return new PersonCollection(modifiedSince);
}


which in turn calls PersonCollection. The PersonCollection has the constructor to initialize the query


PersonIterator has the next to get the users from the system

private NodeDescription fetchNext() throws NamingException
{
boolean readyForNextPage;
do
{
readyForNextPage = this.searchResults == null;
while (!readyForNextPage && this.searchResults.hasMore())
{
SearchResult result = this.searchResults.next();
Attributes attributes = result.getAttributes();
Attribute uidAttribute = attributes.get(LDAPUserRegistry.this.userIdAttributeName);
if (uidAttribute == null)
{
if (LDAPUserRegistry.this.errorOnMissingUID)
{
throw new AlfrescoRuntimeException(
"User returned by user search does not have mandatory user id attribute "
+ attributes);
}
else
{
LDAPUserRegistry.logger
.warn("User returned by user search does not have mandatory user id attribute "
+ attributes);
continue;
}
}
String uid = (String) uidAttribute.get(0);

if (this.uids.contains(uid))
{
LDAPUserRegistry.logger
.warn("Duplicate uid found - there will be more than one person object for this user - "
+ uid);
}

this.uids.add(uid);

if (LDAPUserRegistry.logger.isDebugEnabled())
{
LDAPUserRegistry.logger.debug("Adding user for " + uid);
}

// Apply the mapped properties to the node description
return mapToNode(LDAPUserRegistry.this.personAttributeMapping,
LDAPUserRegistry.this.personAttributeDefaults, result);
}

// Examine the paged results control response for an indication that another page is available
if (!readyForNextPage)
{
readyForNextPage = LDAPUserRegistry.this.ldapInitialContextFactory.hasNextPage(this.ctx,
LDAPUserRegistry.this.queryBatchSize);
}

// Fetch the next page if there is one
if (readyForNextPage)
{
this.searchResults = this.ctx.search(LDAPUserRegistry.this.userSearchBase,
PersonCollection.this.query, this.userSearchCtls);
}
}
while (readyForNextPage);
this.searchResults.close();
this.searchResults = null;
this.ctx.close();
this.ctx = null;
return null;
}


Monday, October 17, 2011

Open Office Trouble shooting

http://wiki.knowledgetree.org/Troubleshooting_OpenOffice.org_Service

testing the service

ps -aux | grep soffice

Tuesday, October 11, 2011

Cron jobs

30 1 * * * --- every day 1:30


http://www.quartz-scheduler.org/docs/tutorials/crontrigger.html


http://www.abunchofutils.com/utils/developer/cron-expression-helper/
http://www.cronmaker.com/

0 0 23 1/1 * ? * --- Every day night 11'o clock

Thursday, October 6, 2011

WebServices for Alfresco

http://wiki.alfresco.com/wiki/IngresTutorial_Alfresco_Web_Service_API_for_Java

org.alfresco.webservice.test.ContentServiceSystemTest

It has more explainations on the content upload through stream

Wednesday, October 5, 2011

Converting InputStream to byte for ByteArrayPartSource

InputStream is = null;
int len;
int size = 1024;
byte[] buf = null;

if (is instanceof ByteArrayInputStream) {
size = is.available();
buf = new byte[size];
len = is.read(buf, 0, size);
}


new FilePart(filename, new ByteArrayPartSource("filename.txt", buf));

How to upload file to Alfresco share using java code

Here the siteid is :testFolders
location to upload is : "/aaa/bbbb

It will upload the file from the local disk to the alfresco site testfolders/documentlibrary/aaa/bbb

Here I have passed the ticket to authenticate with the system



/**
*
*/
package com;

import java.io.File;
import java.io.IOException;

import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.methods.PostMethod;
import org.apache.commons.httpclient.methods.multipart.FilePart;
import org.apache.commons.httpclient.methods.multipart.MultipartRequestEntity;
import org.apache.commons.httpclient.methods.multipart.Part;
import org.apache.commons.httpclient.methods.multipart.StringPart;

import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.HttpException;
import org.apache.commons.httpclient.HttpStatus;
import org.apache.commons.httpclient.methods.GetMethod;





/**
* @author basanagowda.patil
*
*/
public class FileUpload {

public static void uploadDocument(String authTicket, File fileobj, String filename, String filetype, String description, String destination)
{
try
{
String urlString = "http://localhost:8080/alfresco/service/api/upload?alf_ticket="+authTicket;
System.out.println("The upload url:::"+urlString);
HttpClient client = new HttpClient();
PostMethod mPost = new PostMethod(urlString);
//File f1 =fileobj;
Part[] parts = {
new FilePart("filedata",filename,fileobj,filetype,null),
new StringPart("filename", filename),
new StringPart("description", description),
// new StringPart("destination", destination)
new StringPart("description", description),
new StringPart("siteid", "testFolders"),
new StringPart("containerid", "documentLibrary"),
new StringPart("uploaddirectory", "/aaa/bbbb")


};
mPost.setRequestEntity(
new MultipartRequestEntity(parts, mPost.getParams())
);
int statusCode1 = client.executeMethod(mPost);
System.out.println("statusLine>>>" +statusCode1+"......"+ mPost.getStatusLine()+mPost.getResponseBodyAsString());
mPost.releaseConnection();

}
catch (Exception e)
{
System.out.println(e);
}
}
public static void main(String args[])throws IOException
{
// SimpleUpload aw=new SimpleUpload();
//String Ticket=aw.login();
//String ticket="TICKET_3e61ccfa8a11690b10e1a2fb0eeee2c5583b0043";

String alfrescoTiccketURL = "http://localhost:8080/alfresco"+"/service/api/login?u="+"admin"+"&pw="+"admin";




String ticketURLResponse = invokeWebScriptgetRequest(alfrescoTiccketURL);

//ticketURLResponse =
int startindex= ticketURLResponse.indexOf("")+8;
int endindex = ticketURLResponse.indexOf("
");

ticketURLResponse = ticketURLResponse.substring(startindex, endindex);



File f=new File("D:/Testupload/Alfresco_Enterprise_3_4_4_Administrator.pdf");

//FileInputStream is=new FileInputStream(f);
uploadDocument(ticketURLResponse, f,"Alfresco_Enterprise_3_4_4_Administrator.pdf","application/pdf","description",null);

//uploadDocument("TICKET_3ef085c4e24f4e2c53a3fa72b3111e55ee6f0543", f,"47.bmp","image file","application/jpg","workspace://SpacesStore/65a06f8c-0b35-4dae-9835-e38414a99bc1");
}



public static String invokeWebScriptgetRequest(String url){


// Create an instance of HttpClient.
HttpClient client = new HttpClient();

// Create a method instance.
GetMethod method = new GetMethod(url);
/* // Provide custom retry handler is necessary
method.getParams().setParameter(HttpMethodParams.RETRY_HANDLER,
new DefaultHttpMethodRetryHandler(3, false));*/
String response = null;
try {
// Execute the method.
int statusCode = client.executeMethod(method);

if (statusCode != HttpStatus.SC_OK) {
System.err.println("Method failed: " + method.getStatusLine());
}

// Read the response body.
byte[] responseBody = method.getResponseBody();

// Deal with the response.
// Use caution: ensure correct character encoding and is not binary data
response = new String(responseBody);
System.out.println(response);

} catch (HttpException e) {
System.err.println("Fatal protocol violation: " + e.getMessage());
e.printStackTrace();
} catch (IOException e) {
System.err.println("Fatal transport error: " + e.getMessage());
e.printStackTrace();
} finally {
// Release the connection.
method.releaseConnection();
}
return response;

}



}

Tuesday, October 4, 2011

Grails Features

We can have the services declared in the services folder
These services can be used by Contoller by declaring the variable, automatically this service will be
autowired and we can easily access them.


Sending the message to MQ is simple simply put the send command and send the object string.
If you have map it can be converted to json string or xml.
There is a way to get back the object from json by typecasting. Once we are done we can place that message on the MQ.

While putting in the MQ we can use the payloader and pass that payloader object as string.

We can use the groovy variables interchangable with alfresco variables.

We can use any front end. To the front end we can pass the Model and View object. The model can be accessed in the front end.

In the front end we can use JSTL

http://grails.org/doc/latest/

http://grails.org/doc/latest/guide/6.%20The%20Web%20Layer.html

<http://grails.org/doc/latest/guide/6.%20The%20Web%20Layer.html#6.7 Ajax>

JMS Plugin Documentation: http://gpc.github.com/grails-jms/docs/manual/index.html