/*
 * 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 java.util.logging.Logger;
import javax.ejb.EJB;
import javax.ejb.Stateless;
import javax.inject.Named;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;

/**
 *
 * @author skraffmiller
 */
@Stateless
@Named
public class DatasetServiceBean {

    private static final Logger logger = Logger.getLogger(DatasetServiceBean.class.getCanonicalName());
    @EJB
    IndexServiceBean indexService;

    @PersistenceContext(unitName = "VDCNet-ejbPU")
    private EntityManager em;

    public Dataset save(Dataset dataset) {
        Dataset savedDataset = em.merge(dataset);
        String indexingResult = indexService.indexDataset(savedDataset);
        logger.info("during dataset save, indexing result was: " + indexingResult);
        return savedDataset;
    }

    public Dataset find(Object pk) {
        return (Dataset) em.find(Dataset.class, pk);
    }    
    
    public List<Dataset> findByOwnerId(Long ownerId) {
         Query query = em.createQuery("select object(o) from Dataset as o where o.owner.id =:ownerId order by o.id");
         query.setParameter("ownerId", ownerId);
         return query.getResultList();
    }  

    public List<Dataset> findAll() {
        return em.createQuery("select object(o) from Dataset as o order by o.id").getResultList();
    }

}

@@ -214,16 +214,72 @@
 verse;%0A%0A
+import java.util.Collection;%0Aimport java.util.Iterator;%0A
 import j
@@ -882,16 +882,82 @@
 taset) %7B
+   %0A        em.merge(dataset.getVersions().get(0).getMetadata()); 
 %0A       
@@ -995,25 +995,24 @@
 e(dataset);%0A
- 
        Strin
@@ -1067,25 +1067,24 @@
 edDataset);%0A
- 
        logge
@@ -1706,12 +1706,484 @@
 );%0A    %7D
+%0A    %0A    public void removeCollectionElement(Collection coll, Object elem) %7B%0A        coll.remove(elem);%0A        em.remove(elem);%0A    %7D%0A     public void removeCollectionElement(List list,int index) %7B%0A        System.out.println(%22index is %22+index+%22, list size is %22+list.size());%0A        em.remove(list.get(index));%0A        list.remove(index);%0A    %7D  %0A    public void removeCollectionElement(Iterator iter, Object elem) %7B%0A        iter.remove();%0A        em.remove(elem);%0A    %7D
 %0A%0A%7D%0A

Add metadata merge