PublicationTeacher publicationTeacher = new PublicationTeacher(); publicationTeacher.setPublication(publication); publicationTeacher.setTeacher(teacher);  publication.getPublicationTeachers().add(publicationTeacher); teacher.getTeacherPublications().add(publicationTeacher); List newPublications = teacher.getTeacherPublications(); infoPublications = (List) CollectionUtils.collect(newPublications, new Transformer() { public Object transform(Object object) { IPublicationTeacher publicationTeacher = (IPublicationTeacher)object; IPublication publication = publicationTeacher.getPublication(); IPublication publication2 = publication; publication2.setPublicationString(publication.toString()); InfoPublication infoPublication = new InfoPublication(); infoPublication.copyFromDomain(publication2); return infoPublication; } });  ISuportePersistente sp = PersistenceSupportFactory.getDefaultPersistenceSupport(); IPersistentPublicationTeacher persistentPublicationTeacher = sp.getIPersistentPublicationTeacher(); persistentPublicationTeacher.simpleLockWrite(publicationTeacher);  } catch (ExcepcaoPersistencia e) { throw new FenixServiceException(e); }
PublicationTeacher publicationTeacher = new PublicationTeacher(); publicationTeacher.setPublication(publication); publicationTeacher.setTeacher(teacher);  publication.getPublicationTeachers().add(publicationTeacher); teacher.getTeacherPublications().add(publicationTeacher); List newPublications = teacher.getTeacherPublications(); infoPublications = (List) CollectionUtils.collect(newPublications, new Transformer() { public Object transform(Object object) { IPublicationTeacher publicationTeacher = (IPublicationTeacher) object; IPublication publication = publicationTeacher.getPublication(); IPublication publication2 = publication; publication2.setPublicationString(publication.toString()); InfoPublication infoPublication = new InfoPublication(); infoPublication.copyFromDomain(publication2); return infoPublication; } });  ISuportePersistente sp = PersistenceSupportFactory.getDefaultPersistenceSupport(); IPersistentPublicationTeacher persistentPublicationTeacher = sp .getIPersistentPublicationTeacher(); persistentPublicationTeacher.simpleLockWrite(publicationTeacher);
    public List getInfoPublications(ITeacher teacher, IPublication publication,            IPersistentTeacher persistentTeacher, IPersistentPublication persistentPublication)            throws FenixServiceException {        List publicationTeachers = teacher.getTeacherPublications();        List publications = (List) CollectionUtils.collect(publicationTeachers,                new Transformer() {                    public Object transform(Object input) {                        IPublicationTeacher publicationTeacher = (IPublicationTeacher) input;                        return publicationTeacher.getPublication();                    }        });        List infoPublications = new ArrayList();        Iterator iterator = publications.iterator();        while (iterator.hasNext()) {            IPublication publicationTeacher = (IPublication) iterator.next();            if (publicationTeacher.getIdInternal().equals(publication.getIdInternal())) {                throw new ExistingServiceException();            }        }        try {            persistentTeacher.simpleLockWrite(teacher);            persistentPublication.simpleLockWrite(publication);            PublicationTeacher publicationTeacher = new PublicationTeacher();            publicationTeacher.setPublication(publication);            publicationTeacher.setTeacher(teacher);                        publication.getPublicationTeachers().add(publicationTeacher);            teacher.getTeacherPublications().add(publicationTeacher);            List newPublications = teacher.getTeacherPublications();            infoPublications = (List) CollectionUtils.collect(newPublications, new Transformer() {                public Object transform(Object object) {                    IPublicationTeacher publicationTeacher = (IPublicationTeacher)object;                    IPublication publication = publicationTeacher.getPublication();                    IPublication publication2 = publication;                    publication2.setPublicationString(publication.toString());                    InfoPublication infoPublication = new InfoPublication();                    infoPublication.copyFromDomain(publication2);                    return infoPublication;                }            });                        ISuportePersistente sp = PersistenceSupportFactory.getDefaultPersistenceSupport();            IPersistentPublicationTeacher persistentPublicationTeacher = sp.getIPersistentPublicationTeacher();            persistentPublicationTeacher.simpleLockWrite(publicationTeacher);                    } catch (ExcepcaoPersistencia e) {            throw new FenixServiceException(e);        }        return infoPublications;    }