Powered By Blogger

Thursday, August 4, 2016

Tomcat debug ALfresco

Hi Team ,
Follow below steps for setting up the debugger when Alfresco is running as service in the Windows environment.

1.       Navigate the folder where alfresco is been installed in the Command prompt.
Cd D:\Installs\alfrescoServer\tomcat\bin
2.       Now run the below command
.\tomcat7w.exe //ES//alfrescoTomcat
3.       It will open the below popup

4.       In this open the tab Java and add the below values in the Java options
-Xdebug
-Xrunjdwp:transport=dt_socket,address=8000,server=y,suspend=n


5.       Click Apply and OK. By doing this we have made service aware of debugging.
6.       Restart the alfresco server.
7.       In Eclipse Connect to the remote application by configuring the port 8000

8.       Click on Debug and Happy debugging J


Monday, August 1, 2016

Too manu open files

Another important thing to verify is that, your process is not leaking file descriptors or handles, well that's a tedious thing to find out, but you can use lsof command to check how many open file handles is owned by a particular process in UNIX or Linux

Read more: http://javarevisited.blogspot.com/2013/08/how-to-fix-javanetsocketexception-too-many-open-files-java-tomcat-weblogic.html#ixzz4G4VH3yK7

Wednesday, June 8, 2016

Peer association can be done with below code in content model


         
           
               
                  cm:avatarOf
                  false
                  false
             
               
                  cm:content
                  cm:hasAvatar
                  false
                  false
               
           
       


0 or 1 => mandatory = false and many = false
1 => mandatory = true and many = false
0 or more => mandatory = false and many = true
1 or more => mandatory = true and many = true

Peer Association will be dispayed as below
Associations
Association Type
Target Reference
Target Type
cm:avatar
cm:content

Tuesday, May 24, 2016

API to retrieve alfresco user password in multi tenant environment


import java.util.HashMap;
import java.util.Map;

import net.sf.acegisecurity.UserDetails;

import org.alfresco.repo.security.authentication.MutableAuthenticationDao;
import org.alfresco.repo.tenant.TenantUtil;
import org.alfresco.repo.tenant.TenantUtil.TenantRunAsWork;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.extensions.webscripts.Cache;
import org.springframework.extensions.webscripts.DeclarativeWebScript;
import org.springframework.extensions.webscripts.Status;
import org.springframework.extensions.webscripts.WebScriptRequest;

/**
 * This class will be used for getting the alfresco password
 * @author bapatil
 *
 */
public class GetAlfrescoPasswordWebscript extends DeclarativeWebScript {
    private static Log LOGGER = LogFactory.getLog(GetAlfrescoPasswordWebscript.class); 
    MutableAuthenticationDao authenticationDao;   
    
    protected Map executeImpl(final WebScriptRequest req, Status status, Cache cache){
    Map model = new HashMap();
   
    try{
        
       final String userName = req.getParameter("name");
            LOGGER.debug("Get the alfresco password for the user :"+ userName); 
             String currentDomain = userName.substring(userName.lastIndexOf("@")+1,userName.length());
             LOGGER.debug("Domain name of the user is :"+ currentDomain); 
                 
                  String password = TenantUtil.runAsUserTenant(new TenantRunAsWork(){
                       @Override
                       public String doWork() throws Exception{
                           String password;
                           try{ 
                               LOGGER.debug(" userName used to get password is :" + userName);        
                               UserDetails userdetails  = authenticationDao.loadUserByUsername(userName);
                               //LOGGER.debug("userNodeRef of the user" + userdetails.getUsername());
                               password = userdetails.getPassword();
                               LOGGER.debug("password retrieved : " + password);
                              
                           }finally{
                            
                           }
                           return password;
                       }
                   }, "admin", currentDomain);
               
                  LOGGER.debug("password : " + password);
                  model.put("password", password);
                  model.put("message", "success");
                  
       
       // Below are the different attempts, keeping it commented just in case if we need for reference
    //AuthenticationUtil.setRunAsUser("admin");
    //authenticationComponent.setSystemUserAsCurrentUser("clienta.com");
    //authenticationComponent.setCurrentUser("admin@clienta.com");
   
   
    /*LOGGER.debug("Get the alfresco password"); 
            String userName = req.getParameter("name");
            LOGGER.debug("Password for the userName is :" + userName);        
            UserDetails userdetails  = authenticationDao.loadUserByUsername(userName);
            LOGGER.debug("userNodeRef of the user" + userdetails.getUsername());
            String password = userdetails.getPassword();*/
            
   
    /*String updatedpassword =  (String)AuthenticationUtil.runAs(new AuthenticationUtil.RunAsWork() {

@Override
public Object doWork() throws Exception {
// TODO Auto-generated method stub  
LOGGER.debug("Get the alfresco password"); 
           String userName = req.getParameter("name");
           LOGGER.debug("Password for the userName is :" + userName);        
           UserDetails userdetails  = authenticationDao.loadUserByUsername(userName);
           LOGGER.debug("userNodeRef of the user" + userdetails.getUsername());
           return userdetails.getPassword();            
}
},"admin@clienta.com");*/
               
           // String password = DefaultTypeConverter.INSTANCE.convert(String.class, nodeService.getProperty(userNodeRef, ContentModel.PROP_PASSWORD));
   
   
    }catch(Exception e){
    LOGGER.error("Error in getting the alfresco password for the user" , e);
    model.put("message", e.getMessage());
    model.put("password", "");
    }
        
        return model;
    }

   


public MutableAuthenticationDao getAuthenticationDao() {
return authenticationDao;
}

public void setAuthenticationDao(MutableAuthenticationDao authenticationDao) {
this.authenticationDao = authenticationDao;
}

   

}

Monday, May 23, 2016

Searching user from userstore

//execute query to find the user node
var luceneQuery = "@usr\\:username:\"johndoe\"";
var userStoreReference = "user://alfrescoUserStore";
var usersResultList = 
search.luceneSearch(userStoreReference, luceneQuery);
//get the user node and change enable property
var userInTheUserStore = usersResultList[0];
userInTheUserStore.properties["usr:enabled"] = false;
userInTheUserStore.save();

Alfresco Password

Password can be retrieved with the below query

SELECT anp1.node_id,
       anp1.qname_id,       
       anp1.string_value       
FROM alf_node_properties anp1  
   INNER JOIN alf_qname aq1 ON aq1.id = anp1.qname_id   
   INNER JOIN alf_node_properties anp2 ON anp2.node_id = anp1.node_id    
   INNER JOIN alf_qname aq2 ON aq2.id = anp2.qname_id                    
WHERE aq1.local_name = 'password'
AND aq2.local_name = 'username'
AND anp2.string_value = 'admin'

Tuesday, May 17, 2016

The data types ntext and varchar are incompatible in the equal to operator

You can't use text columns in an equal operation of a WHERE clause.  If you are using SQL Express or SQL Server 2005, change your column type from text to either varchar(max) or nvarchar(max)

Monday, March 7, 2016

Alfresco ibatis and Solr debugging

http://smasue.github.io/alf-canned-queries

Above link has the code for creating custom service on top of Alfresco database

http://smasue.github.io/alf-debug-solr
Above link has the code to debug solr queries

Friday, February 19, 2016

stopping batch file to exit intermediately while executing maven, grunt commands

Some of the commands will make batch file to exit inbetween. To avoid this we need to have the call statement. Example is as below

@echo off
rem -------
rem Script for apply AMPs to installed WAR
rem -------


set hpi_source_loc=C:\AlfrescoIRM\hpi
set hpi_contextname=hpi1
set consolidatedBuildLocation=C:\ConsolidatedBuild\allbuilds

echo Create the HPI war
cd %hpi_source_loc%


call grunt tomcatDebug --project=patil-employee-onboarding  --contextname=%hpi_contextname% --env=BLRKA3300
echo Completed the creation of Amp for the HPI code , now copy to the location %consolidatedBuildLocation%
xcopy /s "%hpi_source_loc%\DIST\hpi.war" %consolidatedBuildLocation%

echo Completed the HPI war
pause


In the above code call been added