/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package edu.harvard.iq.dataverse;

import java.util.List;
import javax.ejb.Stateless;
import javax.ejb.TransactionAttribute;
import javax.ejb.TransactionAttributeType;
import javax.inject.Named;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;

/**
 *
 * @author xyang
 */
@Stateless
@Named
public class DataverseUserServiceBean {

    @PersistenceContext(unitName = "VDCNet-ejbPU")
    private EntityManager em;
    
    public String encryptPassword(String plainText) {
        return PasswordEncryption.getInstance().encrypt(plainText);
    }
       
    public DataverseUser save(DataverseUser dataverseUser) {
         return em.merge(dataverseUser);
    }   
}

@@ -908,14 +908,704 @@
 );%0A    %7D
+%0A
    
+ %0A    /*%0A    public List%3CDataverseUser%3E findByUserName(String userName) %7B%0A        Query query = em.createQuery(%22select object(o) from DataverseUser as o where o.userName =:userName%22);%0A        query.setParameter(%22userName%22, userName);%0A        return query.getResultList();%0A    %7D%0A    */%0A    %0A    public DataverseUser findByUserName(String userName) %7B%0A        String query = %22SELECT u from DataverseUser u where u.userName = :userName %22;%0A        DataverseUser user = null;%0A        try %7B%0A            user = (DataverseUser) em.createQuery(query).setParameter(%22userName%22, userName).getSingleResult();%0A        %7D catch (javax.persistence.NoResultException e) %7B%0A        %7D%0A        return user;%0A    %7D
 %0A%7D%0A

Check if a username exists.