IPersistentBibliographicReference persistentBibliographicReference = sp .getIPersistentBibliographicReference(); List bibliographicReferenceList = persistentBibliographicReference .readBibliographicReference(executionCourseFrom.getIdInternal()); if (bibliographicReferenceList != null && bibliographicReferenceList.size() > 0) { ListIterator iterator = bibliographicReferenceList.listIterator(); while (iterator.hasNext()) { IBibliographicReference bibliographicReference = (IBibliographicReference) iterator .next();  IBibliographicReference bibliographicReferenceTo = new BibliographicReference(); persistentBibliographicReference.simpleLockWrite(bibliographicReferenceTo); bibliographicReferenceTo.setExecutionCourse(executionCourseTo); bibliographicReferenceTo.setAuthors(bibliographicReference.getAuthors()); bibliographicReferenceTo.setOptional(bibliographicReference.getOptional()); bibliographicReferenceTo.setReference(bibliographicReference.getReference()); bibliographicReferenceTo.setTitle(bibliographicReference.getTitle()); bibliographicReferenceTo.setYear(bibliographicReference.getYear()); } }  IPersistentEvaluationMethod persistentEvaluationMethod = sp.getIPersistentEvaluationMethod(); IEvaluationMethod evaluationMethod = persistentEvaluationMethod .readByIdExecutionCourse(executionCourseFrom.getIdInternal()); if (evaluationMethod != null) { IEvaluationMethod evaluationMethodTo = persistentEvaluationMethod .readByIdExecutionCourse(executionCourseTo.getIdInternal()); if (evaluationMethodTo == null) { evaluationMethodTo = new EvaluationMethod(); } persistentEvaluationMethod.simpleLockWrite(evaluationMethodTo); evaluationMethodTo.setExecutionCourse(executionCourseTo); evaluationMethodTo.setEvaluationElements(evaluationMethod.getEvaluationElements()); evaluationMethodTo.setEvaluationElementsEn(evaluationMethod.getEvaluationElementsEn()); }
persistentExecutionCourse.simpleLockWrite(executionCourseTo); siteTo.edit(siteFrom.getInitialStatement(), siteFrom.getIntroduction(), siteFrom.getMail(), siteFrom.getAlternativeSite());  copySectionsAndItems(siteFrom, siteTo); copyBibliographicReference(executionCourseFrom, executionCourseTo); copyEvaluationMethod(executionCourseFrom, executionCourseTo);
    public void run(Integer executionCourseIDFrom, Integer executionCourseIDTo)            throws ExcepcaoPersistencia, ExistingServiceException {                ISuportePersistente sp = PersistenceSupportFactory.getDefaultPersistenceSupport();        IPersistentSite persistentSite = sp.getIPersistentSite();        //Course From        ISite siteFrom = persistentSite.readByExecutionCourse(executionCourseIDFrom);        if (siteFrom == null)            return;                IExecutionCourse executionCourseFrom = siteFrom.getExecutionCourse();        //Course To        ISite siteTo = persistentSite.readByExecutionCourse(executionCourseIDTo);        if (siteTo == null)            siteTo = new Site();           //begin copy        persistentSite.simpleLockWrite(siteTo);        //copy course if it isn't        IExecutionCourse executionCourseTo = siteTo.getExecutionCourse();        if (executionCourseTo == null) {            IPersistentExecutionCourse persistentExecutionCourse = sp.getIPersistentExecutionCourse();            executionCourseTo = (IExecutionCourse) persistentExecutionCourse.readByOID(                    ExecutionCourse.class, executionCourseIDTo);            siteTo.setExecutionCourse(executionCourseTo);        }        siteTo.setAlternativeSite(siteFrom.getAlternativeSite());        siteTo.setInitialStatement(siteFrom.getInitialStatement());        siteTo.setIntroduction(siteFrom.getIntroduction());        siteTo.setMail(siteFrom.getMail());        siteTo.setStyle(siteFrom.getStyle());        //copy section and them itens, but before delete them if exists        IPersistentSection persistentSection = sp.getIPersistentSection();        List sectionsFrom = persistentSection.readBySite(siteFrom.getExecutionCourse().getSigla(),                siteFrom.getExecutionCourse().getExecutionPeriod().getName(),                siteFrom.getExecutionCourse().getExecutionPeriod().getExecutionYear().getYear());        if (sectionsFrom != null || sectionsFrom.size() > 0) {            //Delete sections and itens            List sectionsTo = persistentSection.readBySite(siteTo.getExecutionCourse().getSigla(),                    siteTo.getExecutionCourse().getExecutionPeriod().getName(),                    siteTo.getExecutionCourse().getExecutionPeriod().getExecutionYear().getYear());            IPersistentItem persistentItem = sp.getIPersistentItem();            if (sectionsTo != null && sectionsTo.size() > 0) {                ListIterator iteratorSection = sectionsTo.listIterator();                while (iteratorSection.hasNext()) {                    ISection section = (ISection) iteratorSection.next();                    List itens = persistentItem.readAllItemsBySection(section.getIdInternal(),                            section.getSite().getExecutionCourse().getSigla(),                            section.getSite().getExecutionCourse().getExecutionPeriod().getExecutionYear().getYear(),                            section.getSite().getExecutionCourse().getExecutionPeriod().getName());                    if (itens != null && itens.size() > 0) {                        ListIterator iteratorItens = itens.listIterator();                        while (iteratorItens.hasNext()) {                            IItem item = (IItem) iteratorItens.next();                            persistentItem.deleteByOID(Item.class, item.getIdInternal());                        }                    }                    persistentSection.deleteByOID(Section.class, section.getIdInternal());                }            }            //Copy sections and itens            ListIterator iterator = sectionsFrom.listIterator();            sectionsTo = new ArrayList();            while (iterator.hasNext()) {                ISection sectionFrom = (ISection) iterator.next();                ISection sectionNew = new Section();                persistentSection.simpleLockWrite(sectionNew);                sectionNew.setName(sectionFrom.getName());                sectionNew.setSectionOrder(sectionFrom.getSectionOrder());                sectionNew.setSite(siteTo);                //find the superior section                ISection sectionSuperiorTo = null;                if (sectionFrom.getSuperiorSection() != null) {                    ListIterator iteratorsSectionsTo = sectionsTo.listIterator();                    while (iteratorsSectionsTo.hasNext()) {                        ISection sectionTo = (ISection) iteratorsSectionsTo.next();                        if (sectionTo.getName().equals(sectionFrom.getSuperiorSection().getName())) {                            sectionSuperiorTo = sectionTo;                            break;                        }                    }                }                sectionNew.setSuperiorSection(sectionSuperiorTo);                sectionNew.setLastModifiedDate(Calendar.getInstance().getTime());                //section's itens                List itens = persistentItem.readAllItemsBySection(sectionFrom.getIdInternal(),                        sectionFrom.getSite().getExecutionCourse().getSigla(),                        sectionFrom.getSite().getExecutionCourse().getExecutionPeriod().getExecutionYear().getYear(),                        sectionFrom.getSite().getExecutionCourse().getExecutionPeriod().getName());                if (itens != null && itens.size() > 0) {                    ListIterator iteratorItens = itens.listIterator();                    while (iteratorItens.hasNext()) {                        IItem item = (IItem) iteratorItens.next();                                             persistentSection.simpleLockWrite(sectionNew);                        //IItem item2 = sectionNew.insertItem(item.getName(), item.getInformation(), item.getUrgent(), item.getItemOrder());                                                //                        //persistentItem.simpleLockWrite(item2);                        //                    }                }                sectionsTo.add(sectionNew);            }        }        //Copy Bibliographic        IPersistentBibliographicReference persistentBibliographicReference = sp                .getIPersistentBibliographicReference();        List bibliographicReferenceList = persistentBibliographicReference                .readBibliographicReference(executionCourseFrom.getIdInternal());        if (bibliographicReferenceList != null && bibliographicReferenceList.size() > 0) {            ListIterator iterator = bibliographicReferenceList.listIterator();            while (iterator.hasNext()) {                IBibliographicReference bibliographicReference = (IBibliographicReference) iterator                        .next();                IBibliographicReference bibliographicReferenceTo = new BibliographicReference();                persistentBibliographicReference.simpleLockWrite(bibliographicReferenceTo);                bibliographicReferenceTo.setExecutionCourse(executionCourseTo);                bibliographicReferenceTo.setAuthors(bibliographicReference.getAuthors());                bibliographicReferenceTo.setOptional(bibliographicReference.getOptional());                bibliographicReferenceTo.setReference(bibliographicReference.getReference());                bibliographicReferenceTo.setTitle(bibliographicReference.getTitle());                bibliographicReferenceTo.setYear(bibliographicReference.getYear());            }        }        //Copy Evaluation Method        IPersistentEvaluationMethod persistentEvaluationMethod = sp.getIPersistentEvaluationMethod();        IEvaluationMethod evaluationMethod = persistentEvaluationMethod                .readByIdExecutionCourse(executionCourseFrom.getIdInternal());        if (evaluationMethod != null) {            IEvaluationMethod evaluationMethodTo = persistentEvaluationMethod                    .readByIdExecutionCourse(executionCourseTo.getIdInternal());            if (evaluationMethodTo == null) {                evaluationMethodTo = new EvaluationMethod();            }            persistentEvaluationMethod.simpleLockWrite(evaluationMethodTo);            evaluationMethodTo.setExecutionCourse(executionCourseTo);            evaluationMethodTo.setEvaluationElements(evaluationMethod.getEvaluationElements());            evaluationMethodTo.setEvaluationElementsEn(evaluationMethod.getEvaluationElementsEn());        }    }