转换我的alfresco javascript文件到java类

Conversion of my alfresco javascript file into java class

本文关键字:java 文件 javascript 我的 alfresco 转换      更新时间:2023-09-26

我需要将此javascript文件转换为java代码。请帮助

if (document.isContainer && document.displayPath == "/Company Home/User Homes") {
    var owner = document.properties["cm:owner"];
    var pNode = people.getPerson(owner);
    if (pNode!=null && pNode.exists()){
        var userName = pNode.properties.userName;
        var email = pNode.properties.email;
        var randPassword = Math.random().toString(36).substr(2, 30)+"-"+(Date.now());
        people.setPassword(userName, randPassword);
        logger.debug("Invitation mail: User "+userName+" password has been changed.");
        var mail = actions.create("mail");
        //mail.parameters.from = "noreply@customdomain";
        mail.parameters.to = email; 
        mail.parameters.subject = "Welcome to the Site, login: "+userName+", password: "+randPassword;
        mail.parameters.template = companyhome.childByNamePath("Data Dictionary/Email Templates/Invite Email Templates/invite_user_email.ftl");
        var templateModel = new Array();
        templateModel['newPassword'] = randPassword; // use ${newPassword} expression inside template
        mail.parameters.template_model = templateModel;
        mail.executeAsynchronously(document);
        logger.debug("Invitation mail has been sent to "+email);
    } else {
        logger.warn("Invitation mail: User not found: "+owner);
    }
} else {
    logger.warn("Invitation mail: Document "+document.name+" / "+document.nodeRef+" is not a user home folder.");
} 

希望对你有帮助。

public void createUser()
{
    final String randPassword = getRandonPassword();
    final String userName= "someuser";
    final String email = "someuser@example.com";
    authenticationService.setAuthentication(userName, randPassword.toCharArray());
    System.out.println(randPassword);
    AuthenticationUtil.runAs(new AuthenticationUtil.RunAsWork<Void>()
    {
        public Void doWork() throws Exception
        {
            Map<QName, Serializable> properties = new HashMap<QName, Serializable>();
            properties.put(ContentModel.PROP_USERNAME,userName);
            properties.put(ContentModel.PROP_PASSWORD,randPassword);
            properties.put(ContentModel.PROP_EMAIL,email);
            NodeRef personNodeRef = personService.createPerson(properties);
            personService.notifyPerson(userName, randPassword);
            return null;
        }
    }, AuthenticationUtil.getSystemUserName());        
}
private String getRandonPassword()
{
    Calendar calendar = Calendar.getInstance();
    SecureRandom random = new SecureRandom();
    String randomPassword = new BigInteger(130, random).toString(32);
    randomPassword  = randomPassword +"-" + calendar.getTimeInMillis();
    return randomPassword ;        
}