Friday 31 March 2017

To track last modified commit or get last modified timestamp of table in postgresql

PostgreSQL 9.5 let us to track last modified commit.

1. Check track commit is on or off using the following query

  show track_commit_timestamp;

2. If it return "ON" go to step 3 else modify postgresql.conf

Tuesday 10 May 2016

How to get an authentication from Box using mulesoft.

Authenticate to Box using mulesoft.


 <http:listener-config name="HTTP_Listener_Configuration" host="0.0.0.0" port="8081" doc:name="HTTP Listener Configuration"/>
    <box:config name="Box" clientId="05zpeboxxfms6fo7805izrxff9dwbc74" clientSecret="LVD5juoF7ookFVn4uN69Pco3NI4EQeE0" doc:name="Box">
        <box:oauth-callback-config domain="localhost" localPort="8082" remotePort="8082" path="callback" />
    </box:config>
    <objectstore:config name="ObjectStore" objectStore-ref="_defaultInMemoryObjectStore" doc:name="ObjectStore: Configuration" />
    <flow name="boxAuthenticationFlow">
        <http:listener config-ref="HTTP_Listener_Configuration" path="/auth" doc:name="HTTP"/>
        <box:authorize config-ref="Box" doc:name="Box-Authorize"  />
        <set-payload value="#[flowVars._oauthVerifier]" doc:name="Set Payload"/>
        <logger message="#[payload]" level="INFO" doc:name="Logger"/>
        <box:create-folder config-ref="Box" folderName="test folder" doc:name="Box"/>
    </flow>

Sunday 7 February 2016

How to move files from dropbox to Alfresco using mulesoft

The code will work on mule 3.7.

<?xml version="1.0" encoding="UTF-8"?>

<mule xmlns:cmis="http://www.mulesoft.org/schema/mule/cmis" xmlns:file="http://www.mulesoft.org/schema/mule/file" xmlns:mulexml="http://www.mulesoft.org/schema/mule/xml" xmlns:tracking="http://www.mulesoft.org/schema/mule/ee/tracking" xmlns:http="http://www.mulesoft.org/schema/mule/http" xmlns:dropbox="http://www.mulesoft.org/schema/mule/dropbox" xmlns="http://www.mulesoft.org/schema/mule/core" xmlns:doc="http://www.mulesoft.org/schema/mule/documentation"
xmlns:spring="http://www.springframework.org/schema/beans" 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-current.xsd
http://www.mulesoft.org/schema/mule/cmis http://www.mulesoft.org/schema/mule/cmis/current/mule-cmis.xsd
http://www.mulesoft.org/schema/mule/http http://www.mulesoft.org/schema/mule/http/current/mule-http.xsd
http://www.mulesoft.org/schema/mule/dropbox http://www.mulesoft.org/schema/mule/dropbox/current/mule-dropbox.xsd
http://www.mulesoft.org/schema/mule/file http://www.mulesoft.org/schema/mule/file/current/mule-file.xsd
http://www.mulesoft.org/schema/mule/ee/tracking http://www.mulesoft.org/schema/mule/ee/tracking/current/mule-tracking-ee.xsd
http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd
http://www.mulesoft.org/schema/mule/xml http://www.mulesoft.org/schema/mule/xml/current/mule-xml.xsd">
    <dropbox:config name="Dropbox" appKey="${dropboxAppkey}" appSecret="${dropboxAppsecret}" doc:name="Dropbox">
        <dropbox:oauth-callback-config domain="localhost" localPort="8082" remotePort="8082" path="auth"/>
    </dropbox:config>
    <http:listener-config name="HTTP_Listener_Configuration" host="localhost" port="8081" doc:name="HTTP Listener Configuration"/>
    <spring:beans>
     <spring:bean name="getParentPath" class="dropboxalfresco.GetParentPath" id="Bean"/>
    </spring:beans>
    <cmis:config name="ALFRESCO-CMIS" baseUrl="http://localhost:8080/alfresco/api/-default-/public/cmis/versions/1.1/atom" username="${alfrescoUserName}" password="${alfrescoPassword}" useAlfrescoExtension="true" useCookies="true" doc:name="CMIS: Configuration"/>
    <flow name="dropboxalfrescoFlow">
        <http:listener config-ref="HTTP_Listener_Configuration" path="/" doc:name="HTTP"/>
        <expression-filter expression="#[message.inboundProperties.'http.request.uri' != '/favicon.ico']" doc:name="Expression"/>
        <dropbox:authorize config-ref="Dropbox" doc:name="Authourize Dropbox Connection"/>
        <choice doc:name="IsOAuthAccessTokenIdAvailable">
            <when expression="flowVars.OAuthAccessTokenId != null">
                <logger level="INFO" doc:name="LogOAuth Successful"/>
                <set-variable variableName="#['counter']" value="#[0]" doc:name="Variable"/>
                <flow-ref name="Getting-Files-and-Directories" doc:name="Getting-Files-and-Directories"/>
            </when>
            <otherwise>
                <logger level="INFO" doc:name="LogOAuth Failed"/>
                <set-payload value="Authorization to dropbox Failed" doc:name="SetAuthFailedPayload"/>
            </otherwise>
        </choice>
    </flow>
    <flow name="Getting-Files-and-Directories">
        <set-variable variableName="counter" value="#[flowVars['counter']+1]" doc:name="Variable"/>
        <choice doc:name="Root ">
            <when expression="#[flowVars['counter'] == 1]">
                <dropbox:list config-ref="Dropbox" path="/" accessTokenId="#[flowVars.OAuthAccessTokenId]" doc:name="List files &amp; folders"/>
                <mulexml:object-to-xml-transformer doc:name="Object to XML"/>
                <set-variable variableName="isDir" value=" #[xpath3('//contents//isDir')] " doc:name="isDir"/>
                <set-variable variableName="path" value="#[xpath3('//contents//path')] " doc:name="Path"/>
                <logger message="#[&quot;Is Dir  ? &quot; + flowVars.isDir]" level="INFO" doc:name="Logger"/>
                <choice doc:name="File or Directory">
                    <when expression="#[xpath3('//isDir')==false] ">
                        <dropbox:download-file config-ref="Dropbox" path="#[flowVars.path]" accessTokenId="#[flowVars.OAuthAccessTokenId]" doc:name="Download file"/>
                        <file:outbound-endpoint path="C:\Users\Enkindle3\Desktop" outputPattern="fear.jpg" responseTimeout="10000" doc:name="File"/>
                    </when>
                    <otherwise>
                        <logger message="It's a directory" level="INFO" doc:name="Logger"/>
                        <flow-ref name="Getting-Files-and-Directories" doc:name="Getting-Files-and-Directories"/>
                    </otherwise>
                </choice>
            </when>
            <otherwise>
                <logger message="#[flowVars.path]" level="INFO" doc:name="Logger"/>
                <invoke object-ref="getParentPath" method="isZPath" methodArguments="#[flowVars.path]" doc:name="Invoke"/>
                <set-variable variableName="isZPath" value="#[payload]" doc:name="isZPath"/>
                <dropbox:list config-ref="Dropbox" path="#[flowVars.path]" accessTokenId="#[flowVars.OAuthAccessTokenId]" doc:name="List Files &amp; Folders"/>
                <mulexml:object-to-xml-transformer doc:name="Object to XML"/>
                <set-variable variableName="isFolder" value=" #[xpath3('//isDir')] " doc:name="Dir ?"/>
                <invoke object-ref="getParentPath" method="hasContent" methodArguments="#[payload]" doc:name="Invoke"/>
                <set-variable variableName="length" value="#[payload]" doc:name="Contents length"/>
                <choice doc:name="Choice">
                    <when expression="#[flowVars.length &gt; 2 || flowVars.isFolder == &quot; false &quot;]">
                        <logger message="#[payload]" level="INFO" doc:name="Logger"/>
                        <remove-variable variableName="isFolder" doc:name="Remove Dir ?"/>
                        <dropbox:list config-ref="Dropbox" path="#[flowVars.path]" doc:name="Dropbox" accessTokenId="#[flowVars.OAuthAccessTokenId]"/>
                        <mulexml:object-to-xml-transformer doc:name="Object to XML"/>
                        <set-variable variableName="icon" value="#[xpath3('//icon')]" encoding="UTF-8" doc:name="icon"/>
                        <set-variable variableName="path" value="#[xpath3('//path')]" doc:name="Path"/>
                        <logger message="#[payload]" level="INFO" doc:name="Logger"/>
                        <choice tracking:enable-default-events="true" doc:name="Folder or File">
                            <when expression="#[flowVars['icon'] == &quot;folder&quot;]">
                                <set-variable variableName="isDir" value=" #[xpath3('//isDir')] " doc:name="isDir"/>
                                <set-variable variableName="path" value="#[xpath3('//contents//path')] " doc:name="Path"/>
                                <choice doc:name="File or Directory">
                                    <when expression="#[xpath3('//contents//isDir')==false] ">
                                        <dropbox:download-file config-ref="Dropbox" path="#[flowVars.path]" accessTokenId="#[flowVars.OAuthAccessTokenId]" doc:name="Download File"/>
                                        <file:outbound-endpoint path="C:\Users\Enkindle3\Desktop" outputPattern="fear.jpg" responseTimeout="10000" doc:name="File"/>
                                    </when>
                                    <otherwise>
                                        <logger message="It's a sub directory" level="INFO" doc:name="Logger"/>
                                        <flow-ref name="Getting-Files-and-Directories" doc:name="Getting-Files-and-Directories"/>
                                    </otherwise>
                                </choice>
                            </when>
                            <otherwise>
                                <flow-ref name="UploadInToAlfresco" doc:name="UploadInToAlfresco"/>
                            </otherwise>
                        </choice>
                    </when>
                    <otherwise>
                        <logger message="#[&quot;Is Z path &quot; + flowVars.isZPath]" level="INFO" doc:name="Logger"/>
                        <choice doc:name="Choice">
                            <when expression="#[flowVars.isZPath == false]">
                                <dropbox:delete config-ref="Dropbox" path="#[flowVars.path]" accessTokenId="#[flowVars.OAuthAccessTokenId]" doc:name="Delete folder"/>
                                <invoke object-ref="getParentPath" method="getParent" methodArguments="#[flowVars.path]" doc:name="Invoke"/>
                                <set-variable variableName="path" value="#[payload]" doc:name="Path"/>
                                <flow-ref name="Getting-Files-and-Directories" doc:name="Getting-Files-and-Directories"/>
                            </when>
                            <otherwise>
                                <logger message="Everything Moved to Alfresco " level="INFO" doc:name="Logger"/>
                            </otherwise>
                        </choice>
                    </otherwise>
                </choice>
            </otherwise>
        </choice>
    </flow>
    <flow name="UploadInToAlfresco">
        <logger message="#[xpath3('//path')] " level="INFO" doc:name="Logger"/>
        <set-variable variableName="mimeType" value="#[xpath3('//mimeType')]" doc:name="mimeType"/>
        <invoke object-ref="getParentPath" method="getFileName" methodArguments="#[flowVars.path]" doc:name="fileName"/>
        <set-variable variableName="fileName" value="#[payload]" doc:name="File Name"/>
        <dropbox:download-file config-ref="Dropbox" path="#[flowVars.path] " accessTokenId="#[flowVars.OAuthAccessTokenId]" doc:name="Download"/>
        <cmis:create-document-by-path config-ref="ALFRESCO-CMIS" filename="#[flowVars.fileName]" folderPath="/Shared" mimeType="#[flowVars.mimeType]" objectType="cmis:document" versioningState="MAJOR" doc:name="CMIS"/>
        <remove-variable variableName="fileName" doc:name="Remove File Name"/>
        <logger message="#[flowVars.path]" level="INFO" doc:name="Logger"/>
        <dropbox:move config-ref="Dropbox" from="#[flowVars.path] " to="#[&quot;z&quot; + flowVars.path] " doc:name="Move"/>
        <invoke object-ref="getParentPath" method="getParent" methodArguments="#[flowVars.path]" doc:name="Invoke"/>
        <set-variable variableName="path" value="#[payload]" doc:name="Path"/>
        <flow-ref name="Getting-Files-and-Directories" doc:name="Getting-Files-and-Directories"/>
    </flow>
</mule>

Friday 9 October 2015

HttpConnector in mulesoft

This is my first program and first blog in mule soft.

I am sharing the configuration code also

<?xml version="1.0" encoding="UTF-8"?>

<mule xmlns:http="http://www.mulesoft.org/schema/mule/http" xmlns="http://www.mulesoft.org/schema/mule/core" xmlns:doc="http://www.mulesoft.org/schema/mule/documentation"
    xmlns:spring="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-current.xsd
http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd
http://www.mulesoft.org/schema/mule/http http://www.mulesoft.org/schema/mule/http/current/mule-http.xsd">
        <http:listener-config name="HTTP_Listener_Configuration" host="localhost" port="8081"  doc:name="HTTP Listener Configuration"/>

      <flow name="cookbook-helloworldFlow">
         <http:listener config-ref="HTTP_Listener_Configuration" path="/" doc:name="HTTP"/>
          <component class="com.enkindle.Greeting" doc:name="Java"/>
      </flow>

</mule>

Wednesday 30 September 2015

How to get the dataList Items in alfresco using java

public NodeRef getDataListItem(NodeRef actionedUponNodeRef) {
NodeRef vendorItem = null;
String siteShortName = siteService.getSiteShortName(actionedUponNodeRef);
String targetedDataListName = "Vendor";
NodeRef dataListContainer = SiteServiceImpl.getSiteContainer(siteShortName, DATALIST_CONTAINER_ID, true,
siteService, transactionService, taggingService);
List<ChildAssociationRef> dataListsNodes = nodeService.getChildAssocs(dataListContainer);

for (ChildAssociationRef dataList : dataListsNodes) {
if (dataList.getTypeQName().isMatch(ContentModel.ASSOC_CONTAINS)) {
if (nodeService.getProperty(dataList.getChildRef(), ContentModel.PROP_TITLE) != null && nodeService.getProperty(dataList.getChildRef(), ContentModel.PROP_TITLE).toString().equals(targetedDataListName)) {
List<ChildAssociationRef> itemsNodes = nodeService.getChildAssocs(dataList.getChildRef(), ContentModel.ASSOC_CONTAINS, RegexQNamePattern.MATCH_ALL);
   for (ChildAssociationRef item : itemsNodes) {
    System.out.println("ads:" + item.getQName());
    vendorItem = item.getChildRef();
   }
}
}
}
//System.out.println("The dataLists" + dataListNodeRef.);
return vendorItem;
}

How to create Document management and record management site in Alfresco using Java program

How to create DM site in Alfresco using Java program

1. Use the repo tier webscript to invoke siteService to actually create the site.

SiteInfo dmSite = siteService.createSite("site-dashboard", "DM",  " Document Management",  "Document Management", SiteVisibility.PUBLIC);


2. To initialize the site dashboard, use Share tier webscript that uses a remote call to repo tier webscript to creates the site.

ApplicationContext applicationContext = null;
ScriptSiteData scriptSiteData = new ScriptSiteData(requestContext, applicationContext);
Scriptable dmToken = new BaseFunction();

Response response = remoteClient.call("http://localhost:8080/alfresco/s/"); 

dmToken.put("siteid", dmToken, dmShortName); //get dmShortName from response.
dmSiteCreation = scriptSiteData.newPreset("site-dashboard", dmToken);
 

How to create Record management site in Alfresco using java program

It is same way as DM site creation, except initialize the site-dash board

1. Use the repo tier webscript to invoke siteService to actually create the site.

SiteInfo rmSite = siteService.createSite("site-dashboard", "RM",  " Record Management",  "Record Management", SiteVisibility.PUBLIC);


2. To initialize the site dashboard, use Share tier webscript that uses a remote call to repo tier webscript to creates the site.

ApplicationContext applicationContext = null;
ScriptSiteData scriptSiteData = new ScriptSiteData(requestContext, applicationContext);
Scriptable rmToken = new BaseFunction();

Response response = remoteClient.call("http://localhost:8080/alfresco/s/"); 

rmToken.put("siteid", rmToken, rmShortName); //get rmShortName from response.
rmSiteCreation = scriptSiteData.newPreset("rm-site-dashboard", rmToken);